home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / windows / x / 20958 < prev    next >
Encoding:
Text File  |  1993-01-09  |  13.1 KB  |  438 lines

  1. Newsgroups: comp.windows.x
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!saimiri.primate.wisc.edu!ames!pacbell.com!rtech!ingres!mikeg
  3. From: mikeg@Ingres.COM (Mike Glendinning)
  4. Subject: Re: How do I generate valid XDM-AUTHORIZATION-1 ?
  5. Message-ID: <1993Jan9.173603.24271@pony.Ingres.COM>
  6. Organization: Ingres Corporation
  7. References: <fXxsqnx@quack.sac.ca.us>
  8. Date: 9 Jan 93 17:36:03 GMT
  9. Lines: 427
  10.  
  11. It is possible to add hexkeys for XDM-AUTHORIZATION-1 using the
  12. standard 'xauth' command.  The trick is to leave the 8 most
  13. significant bits of the DES key as zero.
  14.  
  15. As you pointed out, the 128-bit hexkey for XDM-AUTHORIZATION-1
  16. is composed of two parts: 64 bits of random data and a 56-bit
  17. DES key.  The 56-bit key is stored in the lower end of a 64-bit
  18. field.  You specify the full 128 bits to 'xauth' with the
  19. random data first.
  20.  
  21. For example, the following 'xauth' command generates a valid
  22. hexkey for XDM-AUTHORIZATION-1:
  23.  
  24.    xauth add :0 XDM-AUTHORIZATION-1 aabbccddeeffaabb00aabbccddeeffaa
  25.  
  26.                                                     ^^ zeros!!
  27.  
  28. Note that the only "win" with XDM-AUTHORIZATION-1 as opposed to
  29. MIT-MAGIC-COOKIE-1 is that the key is not transmitted
  30. in the X connection information by each client and thus you
  31. are not prone to networking snooping (people with PC's on
  32. your Ethernet!).  If you have a secure way of transmitting the
  33. 128-bit hexkey from the server machine to the client machine,
  34. then great!  Otherwise, there is no real benefit.  Unfortunately,
  35. since the key is stored in the Unix filesystem, you're limited by
  36. the security provided there.  And if you are using NFS, then you might
  37. as well forget it anyway, as NFS provides almost No File Security!
  38.  
  39. Also, beware of trying to use *only* XDM-AUTHORIZATION-1.  If you
  40. do this, then R4 based clients will not be able to connect as
  41. they don't know about XDM-AUTHORIZATION-1.  Always add a key for
  42. MIT-MAGIC-COOKIE-1 as well.  You will also potentially get the same
  43. problem with clients from other sources that contain their own Xlib
  44. that doesn't know about XDM-AUTHORIZATION-1.
  45.  
  46. Personally, I have modified 'xauth' to add a "create" command
  47. which will generate random hexkeys automatically.  This is
  48. much easier than getting "ksh" or "perl" to generate a random
  49. cookie for use by the 'xauth' "add" command.  With my changes
  50. (included below), you can just say:
  51.  
  52.    xauth create :0 && xauth create `hostname`:0
  53.  
  54. in order to generate a full set of authorization information for
  55. display number 0 on the local host.  The technique used is exactly
  56. the same as the one used by 'xdm' (in fact, I borrowed the code from
  57. there).  If you just want to generate a random key for a particular
  58. protocol, you can say something like:
  59.  
  60.    xauth create :0 MIT-MAGIC-COOKIE-1
  61.  
  62. The abbreviation "." for "MIT-MAGIC-COOKIE-1" is supported.
  63.  
  64. I would appreciate some comments on these patches, as I am
  65. rather surprised that nobody has done it before.  Of course,
  66. the 'xauth' "add" command is required, but isn't "create"
  67. more useful?
  68.  
  69. By the way, these patches are for the X11R5pl21 version
  70. of 'xauth'.
  71.  
  72. -Mike Glendinning, Ingres UK (mikeg@ingres.com).
  73.  
  74.  
  75. *** Imakefile.orig    Thu Jan  7 16:46:53 1993
  76. --- Imakefile    Fri Jan  8 10:26:25 1993
  77. ***************
  78. *** 1,9 ****
  79.   XCOMM $XConsortium: Imakefile,v 1.14 91/07/16 23:06:17 gildea Exp $
  80.   DEPLIBS = $(DEPXAUTHLIB) $(DEPXMULIB)
  81.   LOCAL_LIBRARIES = $(XAUTHLIB) $(XMULIB)
  82.              SRCS = xauth.c gethost.c process.c parsedpy.c
  83.              OBJS = xauth.o gethost.o process.o parsedpy.o
  84. !         DEFINES = ConnectionFlags $(SIGNAL_DEFINES)
  85.   
  86.   ComplexProgramTarget(xauth)
  87.   
  88. --- 1,14 ----
  89.   XCOMM $XConsortium: Imakefile,v 1.14 91/07/16 23:06:17 gildea Exp $
  90. + #ifdef HasXdmAuth
  91. + XDMAUTH_DEFINES = -DHASXDMAUTH
  92. + #endif
  93.   DEPLIBS = $(DEPXAUTHLIB) $(DEPXMULIB)
  94.   LOCAL_LIBRARIES = $(XAUTHLIB) $(XMULIB)
  95.              SRCS = xauth.c gethost.c process.c parsedpy.c
  96.              OBJS = xauth.o gethost.o process.o parsedpy.o
  97. !         DEFINES = ConnectionFlags $(SIGNAL_DEFINES) $(XDMAUTH_DEFINES)
  98.   
  99.   ComplexProgramTarget(xauth)
  100.   
  101. *** process.c.orig    Thu Jan  7 16:46:53 1993
  102. --- process.c    Fri Jan  8 11:52:46 1993
  103. ***************
  104. *** 40,47 ****
  105.   #define DEFAULT_PROTOCOL "MIT-MAGIC-COOKIE-1"
  106.   #endif
  107.   
  108. ! #define SECURERPC "SUN-DES-1"
  109.   
  110.   #define XAUTH_DEFAULT_RETRIES 10    /* number of competitors we expect */
  111.   #define XAUTH_DEFAULT_TIMEOUT 2        /* in seconds, be quick */
  112.   #define XAUTH_DEFAULT_DEADTIME 600L    /* 10 minutes in seconds */
  113. --- 40,56 ----
  114.   #define DEFAULT_PROTOCOL "MIT-MAGIC-COOKIE-1"
  115.   #endif
  116.   
  117. ! #define MITMAGICCOOKIE        "MIT-MAGIC-COOKIE-1"
  118. ! #define XDMAUTHORIZATION    "XDM-AUTHORIZATION-1"
  119. ! #define SECURERPC        "SUN-DES-1"
  120.   
  121. + #ifndef DEFAULT_RANDOM_FILE
  122. + #define DEFAULT_RANDOM_FILE "/dev/mem"
  123. + #endif
  124. + #define FILE_LIMIT 1024            /* no more than this many buffers */
  125. + #define AUTH_DATA_LEN 16        /* bytes of authorization data */
  126.   #define XAUTH_DEFAULT_RETRIES 10    /* number of competitors we expect */
  127.   #define XAUTH_DEFAULT_TIMEOUT 2        /* in seconds, be quick */
  128.   #define XAUTH_DEFAULT_DEADTIME 600L    /* 10 minutes in seconds */
  129. ***************
  130. *** 86,96 ****
  131.   
  132.   static int do_list(), do_merge(), do_extract(), do_add(), do_remove();
  133.   static int do_help(), do_source(), do_info(), do_exit();
  134. ! static int do_quit(), do_questionmark();
  135.   
  136.   static CommandTable command_table[] = {    /* table of known commands */
  137.       { "add",      2, 3, do_add,
  138.       "add dpyname protoname hexkey   add entry" },
  139.       { "exit",     3, 4, do_exit,
  140.       "exit                           save changes and exit program" },
  141.       { "extract",  3, 7, do_extract,
  142. --- 95,107 ----
  143.   
  144.   static int do_list(), do_merge(), do_extract(), do_add(), do_remove();
  145.   static int do_help(), do_source(), do_info(), do_exit();
  146. ! static int do_quit(), do_questionmark(), do_create();
  147.   
  148.   static CommandTable command_table[] = {    /* table of known commands */
  149.       { "add",      2, 3, do_add,
  150.       "add dpyname protoname hexkey   add entry" },
  151. +     { "create",   2, 6, do_create,
  152. +     "create dpyname [protoname]     create random entry" },
  153.       { "exit",     3, 4, do_exit,
  154.       "exit                           save changes and exit program" },
  155.       { "extract",  3, 7, do_extract,
  156. ***************
  157. *** 1091,1096 ****
  158. --- 1102,1235 ----
  159.       return errors;
  160.   }
  161.   
  162. + #ifdef HASXDMAUTH
  163. + static longtochars (l, c)
  164. +     long l;
  165. +     unsigned char *c;
  166. + {
  167. +     c[0] = (l >> 24) & 0xff;
  168. +     c[1] = (l >> 16) & 0xff;
  169. +     c[2] = (l >> 8) & 0xff;
  170. +     c[3] = l & 0xff;
  171. + }
  172. + static int sumfile (name, sum)
  173. +     char *name;
  174. +     long sum[2];
  175. + {
  176. +     long buf[1024*2];
  177. +     int cnt;
  178. +     int fd;
  179. +     int loops;
  180. +     int reads;
  181. +     int i;
  182. +     fd = open (name, 0);
  183. +     if (fd < 0)
  184. +     return 0;
  185. +     reads = FILE_LIMIT;
  186. +     while ((cnt = read (fd, buf, sizeof (buf))) > 0 && --reads > 0) {
  187. +     loops = cnt / (2 * sizeof (long));
  188. +     for (i = 0; i < loops; i += 2) {
  189. +         sum[0] += buf[i];
  190. +         sum[1] += buf[i+1];
  191. +     }
  192. +     }
  193. +     close (fd);
  194. +     return 1;
  195. + }
  196. + #endif
  197. + static genauth(authstr, len)
  198. +     char *authstr;
  199. +     int len;
  200. + {
  201. +     long ldata[2];
  202. + #ifdef ITIMER_REAL
  203. +     {
  204. +     struct timeval  now;
  205. +     struct timezone zone;
  206. +     gettimeofday (&now, &zone);
  207. +     ldata[0] = now.tv_sec;
  208. +     ldata[1] = now.tv_usec;
  209. +     }
  210. + #else
  211. +     {
  212. +     long time ();
  213. +     ldata[0] = time ((long *) 0);
  214. +     ldata[1] = getpid ();
  215. +     }
  216. + #endif
  217. + #ifdef HASXDMAUTH
  218. +     {
  219. +     typedef unsigned char auth_cblock[8];   /* block size */
  220. +     typedef struct auth_ks_struct { auth_cblock _; }
  221. +                       auth_wrapper_schedule[16];
  222. +     int i, bit, authi;
  223. +     char *authc;
  224. +     auth_wrapper_schedule schedule;
  225. +     unsigned char data[8];
  226. +     static unsigned char key[8];
  227. +     static int xdmcpauthinited = 0;
  228. +     longtochars (ldata[0], data+0);
  229. +     longtochars (ldata[1], data+4);
  230. +     if (!xdmcpauthinited) {
  231. +         char *name, *getenv();
  232. +         long sum[2];
  233. +         unsigned char tmpkey[8];
  234. +         name = getenv ("RANDOM_FILE");
  235. +         if (name == NULL)
  236. +             name = DEFAULT_RANDOM_FILE;
  237. +         if (!sumfile (name, sum)) {
  238. +             sum[0] = time ((long *) 0);
  239. +             sum[1] = time ((long *) 0);
  240. +         }
  241. +         longtochars (sum[0], tmpkey+0);
  242. +         longtochars (sum[1], tmpkey+4);
  243. +         tmpkey[0] = 0;
  244. +         _XdmcpWrapperToOddParity (tmpkey, key);
  245. +         xdmcpauthinited = 1;
  246. +     }
  247. +     _XdmcpAuthSetup (key, schedule);
  248. +     for (i = 0; i < len; i++) {
  249. +         authi = 0;
  250. +         for (bit = 1; bit < 256; bit <<= 1) {
  251. +             _XdmcpAuthDoIt (data, data, schedule, 1);
  252. +             if (data[0] + data[1] & 0x4)
  253. +                 authi |= bit;
  254. +         }
  255. +         authc = hex_table[authi & 0xff];
  256. +         authstr[i*2] = authc[0];
  257. +         authstr[i*2+1] = authc[1];
  258. +     }
  259. +     authstr[len*2] = '\0';
  260. +     }
  261. + #else
  262. +     {
  263. +     int i, seed, value;
  264. +     char *authc;
  265. +     seed = (ldata[0]) + (ldata[1] << 16);
  266. +     srand (seed);
  267. +     for (i = 0; i < len; i++)
  268. +     {
  269. +         value = rand ();
  270. +         authc = hex_table[value & 0xff];
  271. +         authstr[i*2] = authc[0];
  272. +         authstr[i*2+1] = authc[1];
  273. +     }
  274. +     authstr[len*2] = '\0';
  275. +     }
  276. + #endif
  277. + }
  278.   /* ARGSUSED */
  279.   static int remove_entry (inputfilename, lineno, auth, data)
  280.       char *inputfilename;
  281. ***************
  282. *** 1466,1471 ****
  283. --- 1605,1691 ----
  284.   
  285.       xauth_modified = True;
  286.       return 0;
  287. + }
  288. + /*
  289. +  * create displayname protocolname
  290. +  */
  291. + static int do_create (inputfilename, lineno, argc, argv)
  292. +     char *inputfilename;
  293. +     int lineno;
  294. +     int argc;
  295. +     char **argv;
  296. + { 
  297. +     int p1, p2;
  298. +     char *dpyname;
  299. +     char *protoname;
  300. +     char authstr[AUTH_DATA_LEN*2+1];
  301. +     char *addcmds[5];
  302. +     int errors;
  303. +     if (argc < 2 || argc > 3 || !argv[1]) {
  304. +     prefix (inputfilename, lineno);
  305. +     badcommandline (argv[0]);
  306. +     return 1;
  307. +     }
  308. +     dpyname = argv[1];
  309. +     addcmds[0] = "create"; /* OK since do_add won't check! */
  310. +     addcmds[1] = dpyname;
  311. +     addcmds[2] = ""; /* protocol filled-in later on */
  312. +     addcmds[3] = authstr;
  313. +     addcmds[4] = NULL;
  314. +     if (argc == 3 && argv[2]) {
  315. +     protoname = argv[2];
  316. +     if (strcmp (protoname, DEFAULT_PROTOCOL_ABBREV) == 0) {
  317. +         protoname = DEFAULT_PROTOCOL;
  318. +     }
  319. +     p1 = (strcmp (protoname, MITMAGICCOOKIE) == 0);
  320. + #ifdef HASXDMAUTH
  321. +     p2 = (strcmp (protoname, XDMAUTHORIZATION) == 0);
  322. + #else
  323. +     p2 = 0;
  324. + #endif
  325. +     if (p1 || p2) {
  326. +         genauth(authstr, AUTH_DATA_LEN);
  327. +         if (p2) {
  328. +             authstr[16] = '0';
  329. +             authstr[17] = '0';
  330. +         }
  331. +         addcmds[2] = protoname;
  332. +         errors = do_add (inputfilename, lineno, 4, addcmds);
  333. +     }
  334. +     else {
  335. +         prefix (inputfilename, lineno);
  336. +         fprintf (stderr,
  337. +                  "don't know how to create protocol %s\n", protoname);
  338. +         return 1;
  339. +     }
  340. +     }
  341. +     else {
  342. +     /*
  343. +      * by default, generate both MIT-MAGIC-COOKIE-1 and XDM-AUTHORIZATION-1
  344. +      */
  345. +     genauth(authstr, AUTH_DATA_LEN);
  346. +     addcmds[2] = MITMAGICCOOKIE;
  347. +     errors = do_add (inputfilename, lineno, 4, addcmds);
  348. + #ifdef HASXDMAUTH
  349. +     if (errors)
  350. +         return errors;
  351. +     genauth(authstr, AUTH_DATA_LEN);
  352. +     authstr[16] = '0';
  353. +     authstr[17] = '0';
  354. +     addcmds[2] = XDMAUTHORIZATION;
  355. +     errors = do_add (inputfilename, lineno, 4, addcmds);
  356. + #endif
  357. +     }
  358. +     return errors;
  359.   }
  360.   
  361.   /*
  362. *** xauth.man.orig    Thu Jan  7 16:46:54 1993
  363. --- xauth.man    Fri Jan  8 09:35:28 1993
  364. ***************
  365. *** 57,62 ****
  366. --- 57,70 ----
  367.   A protocol name consisting of just a 
  368.   single period is treated as an abbreviation for \fIMIT-MAGIC-COOKIE-1\fP.
  369.   .TP 8
  370. + .B "create \fIdisplayname \fR[\fIprotocolname\fP]"
  371. + An authorization entry for the indicated display using the given protocol
  372. + is created using a random number generator and added to the authorization file.
  373. + A protocol name consisting of just a 
  374. + single period is treated as an abbreviation for \fIMIT-MAGIC-COOKIE-1\fP.
  375. + If the protocol name is not specified, then authorization entries are
  376. + created for all supported protocols.
  377. + .TP 8
  378.   .B "[n]extract \fIfilename displayname..."
  379.   Authorization entries for each of the specified displays are written to the 
  380.   indicated file.  If the \fInextract\fP command is used, the entries are written
  381. ***************
  382. *** 111,117 ****
  383.   .B "?"
  384.   A short list of the valid commands is printed on the standard output.
  385.   .SH "DISPLAY NAMES"
  386. ! Display names for the \fIadd\fP, \fI[n]extract\fP, \fI[n]list\fP,
  387.   \fI[n]merge\fP, and \fIremove\fP commands use the same format as the
  388.   DISPLAY environment variable and the common \fI-display\fP command line
  389.   argument.  Display-specific information (such as the screen number)
  390. --- 119,125 ----
  391.   .B "?"
  392.   A short list of the valid commands is printed on the standard output.
  393.   .SH "DISPLAY NAMES"
  394. ! Display names for the \fIadd\fP, \fIcreate\fP, \fI[n]extract\fP, \fI[n]list\fP,
  395.   \fI[n]merge\fP, and \fIremove\fP commands use the same format as the
  396.   DISPLAY environment variable and the common \fI-display\fP command line
  397.   argument.  Display-specific information (such as the screen number)
  398. ***************
  399. *** 153,157 ****
  400.   Copyright 1989, Massachusetts Institute of Technology.
  401.   .br
  402.   See \fIX(1)\fP for a full statement of rights and permissions.
  403. ! .SH AUTHOR
  404.   Jim Fulton, MIT X Consortium
  405. --- 161,167 ----
  406.   Copyright 1989, Massachusetts Institute of Technology.
  407.   .br
  408.   See \fIX(1)\fP for a full statement of rights and permissions.
  409. ! .SH AUTHORS
  410.   Jim Fulton, MIT X Consortium
  411. + .br
  412. + Mike Glendinning, Ingres Corporation
  413.