README revision 27702724
127702724Smrg
227702724Smrg
327702724Smrg		     A Sample Authorization Protocol for X
427702724Smrg
527702724Smrg
627702724SmrgOverview
727702724Smrg
827702724SmrgThe following note describes a very simple mechanism for providing individual
927702724Smrgaccess to an X Window System display.  It uses existing core protocol and
1027702724Smrglibrary hooks for specifying authorization data in the connection setup block
1127702724Smrgto restrict use of the display to only those clients that show that they
1227702724Smrgknow a server-specific key called a "magic cookie".  This mechanism is *not*
1327702724Smrgbeing proposed as an addition to the Xlib standard; among other reasons, a
1427702724Smrgprotocol extension is needed to support more flexible mechanisms.  We have
1527702724Smrgimplemented this mechanism already; if you have comments, please send them
1627702724Smrgto us.
1727702724Smrg
1827702724SmrgThis scheme involves changes to the following parts of the sample release:
1927702724Smrg
2027702724Smrg    o  xdm
2127702724Smrg	-  generate random magic cookie and store in protected file
2227702724Smrg	-  pass name of magic cookie file to server
2327702724Smrg	-  when user logs in, add magic cookie to user's auth file
2427702724Smrg	-  when user logs out, generate a new cookie for server
2527702724Smrg
2627702724Smrg    o  server
2727702724Smrg	-  a new command line option to specify cookie file
2827702724Smrg	-  check client authorization data against magic cookie
2927702724Smrg	-  read in cookie whenever the server resets
3027702724Smrg	-  do not add local machine to host list if magic cookie given
3127702724Smrg
3227702724Smrg    o  Xlib
3327702724Smrg	-  read in authorization data from file
3427702724Smrg	-  find data for appropriate server
3527702724Smrg	-  send authorization data if found
3627702724Smrg
3727702724Smrg    o  xauth [new program to manage user auth file]
3827702724Smrg	-  add entries to user's auth file
3927702724Smrg	-  remove entries from user's auth file
4027702724Smrg
4127702724SmrgThis mechanism assumes that the superuser and the transport layer between 
4227702724Smrgthe client and the server is secure.  Organizations that desire stricter
4327702724Smrgsecurity are encouraged to look at systems such as Kerberos (at Project
4427702724SmrgAthena).
4527702724Smrg
4627702724Smrg
4727702724SmrgDescription
4827702724Smrg
4927702724SmrgThe sample implementation will use the xdm Display Manager to set up and
5027702724Smrgcontrol the server's authorization file.  Sites that do not run xdm will
5127702724Smrgneed to build their own mechanisms.  
5227702724Smrg
5327702724SmrgXdm uses a random key (seeded by the system time and check sum of /dev/kmem)
5427702724Smrgto generate a unique sequence of characters at 16 bytes long.  This sequence
5527702724Smrgwill be written to a file which is made readable only by the server.  The
5627702724Smrgserver will then be started with a command line option instructing it to use
5727702724Smrgthe contents of the file as the magic cookie for connections that include
5827702724Smrgauthorization data.  This will also disable the server from adding the local
5927702724Smrgmachine's address to the initial host list.  Note that the actual cookie must
6027702724Smrgnot be stored on the command line or in an environment variable, to prevent
6127702724Smrgit from being publicly obtainable by the "ps" command.
6227702724Smrg
6327702724SmrgIf a client presents an authorization name of "MIT-MAGIC-COOKIE-1" and
6427702724Smrgauthorization data that matches the magic cookie, that client is allowed
6527702724Smrgaccess.  If the name or data does not match and the host list is empty,
6627702724Smrgthat client will be denied access.  Otherwise, the existing host-based access
6727702724Smrgcontrol will be used.  Since any client that is making a connection from a
6827702724Smrgmachine on the host list will be granted access even if their authorization
6927702724Smrgdata is incorrect, sites are strongly urged not to set up any default hosts
7027702724Smrgusing the /etc/X*.hosts files.  Granting access to other machines should be
7127702724Smrgdone by the user's session manager instead.
7227702724Smrg
7327702724SmrgAssuming the server is configured with an empty host list, the existence of the
7427702724Smrgcookie is sufficient to ensure there will be no unauthorized access to the
7527702724Smrgdisplay.  However, xdm will (continue to) work to minimize the chances of
7627702724Smrgspoofing on servers that do not support this authorization mechanism.  This
7727702724Smrgwill be done by grabbing the server and the keyboard after opening the display.
7827702724SmrgThis action will be surrounded by a timer which will kill the server if the
7927702724Smrggrabs cannot be done within several seconds.  [This level of security is now
8027702724Smrgimplemented in patches already sent out.]
8127702724Smrg
8227702724SmrgAfter the user logs in, xdm will add authorization entries for each of the
8327702724Smrgserver machine's network addresses to the user's authorization file (the format
8427702724Smrgof which is described below).  This file will usually be named .Xauthority in
8527702724Smrgthe users's home directory; will be owned by the user (as specified by the
8627702724Smrgpw_uid and pw_gid fields in the user's password entry), and will be accessible
8727702724Smrgonly to the user (no group access).  This file will contain authorization data
8827702724Smrgfor all of the displays opened by the user.
8927702724Smrg
9027702724SmrgWhen the session terminates, xdm will generate and store a new magic cookie
9127702724Smrgfor the server.  Then, xdm will shutdown its own connection and send a
9227702724SmrgSIGHUP to the server process, which should cause the server to reset.  The
9327702724Smrgserver will then read in the new magic cookie.
9427702724Smrg
9527702724SmrgTo support accesses (both read and write) from multiple machines (for use in
9627702724Smrgenvironments that use distributed file systems), file locking is done using
9727702724Smrghard links.  This is done by creat'ing (sic) a lock file and then linking it
9827702724Smrgto another name in the same directory.  If the link-target already exists,
9927702724Smrgthe link will fail, indicating failure to obtain the lock.  Linking is used
10027702724Smrginstead of just creating the file read-only since link will fail even for
10127702724Smrgthe superuser.
10227702724Smrg
10327702724SmrgProblems and Solutions
10427702724Smrg
10527702724SmrgThere are a few problems with .Xauthority as described.  If no home directory
10627702724Smrgexists, or if xdm cannot create a file there (disk full), xdm stores the
10727702724Smrgcookie in a file in a resource-specified back-up directory, and sets an
10827702724Smrgenvironment variable in the user's session (called XAUTHORITY) naming this
10927702724Smrgfile.  There is also the problem that the locking attempts will need to be
11027702724Smrgtimed out, due to a leftover lock.  Xdm, again, creates a file and set an
11127702724Smrgenvironment variable.  Finally, the back-up directory might be full.  Xdm,
11227702724Smrgas a last resort, provides a function key binding that allows a user to log
11327702724Smrgin without having the authorization data stored, and with host-based access
11427702724Smrgcontrol disabled.
11527702724Smrg
11627702724SmrgXlib
11727702724Smrg
11827702724SmrgXOpenDisplay in Xlib was enhanced to allow specification of authorization
11927702724Smrginformation.  As implied above, Xlib looks for the data in the
12027702724Smrg.Xauthority file of the home directory, or in the file pointed at by the
12127702724SmrgXAUTHORITY environment variable instead if that is defined.  This required
12227702724Smrgno programmatic interface change to Xlib.  In addition, a new Xlib routine
12327702724Smrgis provided to explicitly specify authorization.
12427702724Smrg
12527702724Smrg	XSetAuthorization(name, namelen, data, datalen)
12627702724Smrg		int namelen, datalen;
12727702724Smrg		char *name, *data;
12827702724Smrg
12927702724SmrgThere are three types of input:
13027702724Smrg
13127702724Smrg	name NULL, data don't care	- use default authorization mechanism.
13227702724Smrg	name non-NULL, data NULL	- use the named authorization; get
13327702724Smrg					  data from that mechanism's default.
13427702724Smrg	name non-NULL, data non-NULL	- use the given authorization and data.
13527702724Smrg					
13627702724SmrgThis interface is used by xdm and might also be used by any other
13727702724Smrgapplications that wish to explicitly set the authorization information.
13827702724Smrg
13927702724SmrgAuthorization File
14027702724Smrg
14127702724SmrgThe .Xauthority file is a binary file consisting of a sequence of entries
14227702724Smrgin the following format:
14327702724Smrg
14427702724Smrg	2 bytes		Family value (second byte is as in protocol HOST)
14527702724Smrg	2 bytes		address length (always MSB first)
14627702724Smrg	A bytes		host address (as in protocol HOST)
14727702724Smrg	2 bytes		display "number" length (always MSB first)
14827702724Smrg	S bytes		display "number" string
14927702724Smrg	2 bytes		name length (always MSB first)
15027702724Smrg	N bytes		authorization name string
15127702724Smrg	2 bytes		data length (always MSB first)
15227702724Smrg	D bytes		authorization data string
15327702724Smrg
15427702724SmrgThe format is binary for easy processing, since authorization information
15527702724Smrgusually consists of arbitrary data.  Host addresses are used instead of
15627702724Smrgnames to eliminate potentially time-consuming name resolutions in
15727702724SmrgXOpenDisplay.  Programs, such as xdm, that initialize the user's
15827702724Smrgauthorization file will have to do the same work as the server in finding
15927702724Smrgaddresses for all network interfaces.  If more than one entry matches the
16027702724Smrgdesired address, the entry that is chosen is implementation-dependent.  In
16127702724Smrgour implementation, it is always the first in the file.
16227702724Smrg
16327702724SmrgThe Family is specified in two bytes to allow out-of-band values
16427702724Smrg(i.e. values not in the Protocol) to be used.  In particular,
16527702724Smrgtwo new values "FamilyLocal" and "FamilyWild" are defined.  FamilyLocal
16627702724Smrgrefers to any connections using a non-network method of connetion from the
16727702724Smrglocal machine (Unix domain sockets, shared memory, loopback serial line).
16827702724SmrgIn this case the host address is specified by the data returned from
16927702724Smrggethostname() and better be unique in a collection of machines
17027702724Smrgwhich share NFS directories.  FamilyWild is currently used only
17127702724Smrgby xdm to communicate authorization data to the server.  It matches
17227702724Smrgany family/host address pair.
17327702724Smrg
17427702724SmrgFor FamilyInternet, the host address is the 4 byte internet address, for
17527702724SmrgFamilyDecnet, the host address is the byte decnet address, for FamilyChaos
17627702724Smrgthe address is also two bytes.
17727702724Smrg
17827702724SmrgThe Display Number is the ascii representation of the display number
17927702724Smrgportion of the display name.  It is in ascii to allow future expansion
18027702724Smrgto PseudoRoots or anything else that might happen.
18127702724Smrg
18227702724SmrgA utility called "xauth" will be provided for editing and viewing the
18327702724Smrgcontents of authorization files.  Note that the user's authorization file is
18427702724Smrgnot the same as the server's magic cookie file.
185