Git init
[framework/uifw/xorg/proto/x11proto-xext.git] / specs / security.xml
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3                    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
4 <!--translated from security.tex, on 2010-06-27 15:29:00,
5 by TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)
6 xhtml,docbook,html,refcaption -->
7
8 <book id="security">
9
10 <bookinfo>
11    <title>Security Extension Specification</title>
12    <subtitle>X Consortium Standard</subtitle>
13    <releaseinfo>X Version 11, Release 6.8</releaseinfo>
14    <date>November 15, 1996</date>
15    <authorgroup>
16       <author>
17          <firstname>David</firstname><surname>Wiggins</surname>
18       </author>
19    </authorgroup>
20    <corpname>X Consortium Standard</corpname>
21    <copyright><year>1996</year><holder>X Consortium</holder></copyright>
22    <releaseinfo>Version 7.1</releaseinfo>
23    <affiliation><orgname>X Consortium</orgname></affiliation>
24    <productnumber>X Version 11, Release 6.8</productnumber>
25
26 <legalnotice>
27
28 <para>THE SOFTWARE IS PROVIDED &ldquo;AS IS&rdquo;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</para>
29
30 <para>Except as contained in this notice, the name of the X Consortium shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the X Consortium.</para>
31
32 </legalnotice>
33
34 </bookinfo>
35
36 <chapter id="introduction">
37 <title>Introduction</title>
38
39 <para>
40 The Security extension contains new protocol needed to provide enhanced X
41 server security. The Security extension should not be exposed to untrusted
42 clients (defined below).
43 </para>
44
45 </chapter>
46
47 <chapter id="requests">
48 <title>Requests</title>
49
50 <sect1 id="securityqueryversion">
51 <title>SecurityQueryVersion</title>
52 <para>
53 This request returns the major and minor version numbers of this extension.
54 </para>
55
56 <para>SecurityQueryVersion</para>
57
58 <informaltable>
59   <tgroup cols="2">
60     <tbody>
61       <row>
62         <entry align="left">
63           <para>client-major-version</para>
64         </entry>
65         <entry align="left">
66           <para>CARD16</para>
67         </entry>
68       </row>
69       <row>
70         <entry align="left">
71           <para>client-minor-version</para>
72         </entry>
73         <entry align="left">
74           <para>CARD16</para>
75         </entry>
76       </row>
77       <row>
78         <entry align="left">
79           <para>=&gt;</para>
80         </entry>
81       </row>
82       <row>
83         <entry align="left">
84           <para>server-major-version</para>
85         </entry>
86         <entry align="left">
87           <para>CARD16</para>
88         </entry>
89       </row>
90       <row>
91         <entry align="left">
92           <para>server-minor-version</para>
93         </entry>
94         <entry align="left">
95           <para>CARD16</para>
96         </entry>
97       </row>
98       <row>
99         <entry align="left">
100           <para></para>
101         </entry>
102       </row>
103     </tbody>
104   </tgroup>
105 </informaltable>
106
107 <para>
108 The client-major-version and client-minor-version numbers indicate what
109 version of the protocol the client wants the server to implement. The
110 server-major-version and the server-minor-version numbers returned
111 indicate the protocol this extension actually supports. This might not
112 equal the version sent by the client. An implementation can (but need not)
113 support more than one version simultaneously.  The server-major-version
114 and server-minor-version allow the creation of future revisions of the
115 Security protocol that may be necessary. In general, the major version
116 would increment for incompatible changes, and the minor version would
117 increment for small, upward-compatible changes. Servers that support
118 the protocol defined in this document will return a server-major-version
119 of one (1), and a server-minor-version of zero (0).
120 </para>
121
122 <para>
123 Clients using the Security extension must issue a SecurityQueryVersion
124 request before any other Security request in order to negotiate a compatible
125 protocol version; otherwise, the client will get undefined behavior
126 (Security may or may not work).
127 </para>
128 </sect1>
129
130 <sect1 id="securitygenerateauthentication">
131 <title>SecurityGenerateAuthorization</title>
132
133 <para>
134 This request causes the server to create and return a new authorization with
135 specific characteristics. Clients can subsequently connect using the new
136 authorization and will inherit some of the characteristics of the
137 authorization.
138 </para>
139
140 <para>
141 SecurityGenerateAuthorization
142 </para>
143 <informaltable>
144   <tgroup cols="2">
145     <tbody>
146       <row>
147         <entry align="left">
148           <para>authorization-protocol-name</para>
149         </entry>
150         <entry align="left">
151           <para>STRING8</para>
152         </entry>
153       </row>
154       <row>
155         <entry align="left">
156           <para>authorization-protocol-data</para>
157         </entry>
158         <entry align="left">
159           <para>STRING8</para>
160         </entry>
161       </row>
162       <row>
163         <entry align="left">
164           <para>value-mask</para>
165         </entry>
166         <entry align="left">
167           <para>BITMASK</para>
168         </entry>
169       </row>
170       <row>
171         <entry align="left">
172           <para>value-list</para>
173         </entry>
174         <entry align="left">
175           <para>LISTofVALUE</para>
176         </entry>
177       </row>
178       <row>
179         <entry align="left">
180           <para>=></para>
181         </entry>
182         <entry>
183         </entry>
184       </row>
185       <row>
186         <entry align="left">
187           <para>authorization-id</para>
188         </entry>
189         <entry align="left">
190           <para>AUTHID</para>
191         </entry>
192       </row>
193       <row>
194         <entry align="left">
195           <para>authorization-data-return</para>
196         </entry>
197         <entry align="left">
198           <para>STRING8</para>
199         </entry>
200       </row>
201       <row>
202         <entry align="left">
203           <para></para>
204         </entry>
205         <entry>
206         </entry>
207       </row>
208     </tbody>
209   </tgroup>
210 </informaltable>
211
212 <para>
213 Errors: <function>AuthorizationProtocol</function>, <function>Value</function>, <function>Alloc</function>
214 </para>
215
216 <para>
217 authorization-protocol-name is the name of the authorization method for
218 which the server should generate a new authorization that subsequent
219 clients can use to connect to the server. If the authorization-protocol-name
220 is not one that the server supports, or if authorization-protocol-data
221 does not make sense for the given authorization-protocol-name, an
222 AuthorizationProtocol error results.
223 </para>
224
225 <para>
226 authorization-protocol-data is authorization-method specific data that can
227 be used in some way to generate the authorization.
228 </para>
229
230 <note><para>
231 In this version of the extension, the only authorization method
232 required to be supported is "MIT-MAGIC-COOKIE-1" with any amount
233 of authorization-protocol-data (including none). The server may use the
234 authorization-protocol-data as an additional source of randomness used
235 to generate the authorization. Other authorization methods can supply
236 their own interpretation of authorization-protocol-data.
237 </para></note>
238
239 <para>
240 The value-mask and value-list specify attributes of the authorization
241 that are to be explicitly initialized. The possible values are:
242 </para>
243
244 <informaltable>
245   <tgroup cols="3">
246     <tbody>
247       <row rowsep="1">
248         <entry align="left">
249           <para></para>
250         </entry>
251       </row>
252       <row rowsep="1">
253         <entry align="left">
254           <para>Attribute</para>
255         </entry>
256         <entry align="left">
257           <para>Type</para>
258         </entry>
259         <entry align="left">
260           <para>Default</para>
261         </entry>
262       </row>
263       <row>
264         <entry align="left">
265           <para>timeout</para>
266         </entry>
267         <entry align="left">
268           <para>CARD32</para>
269         </entry>
270         <entry align="left">
271           <para>60</para>
272         </entry>
273       </row>
274       <row>
275         <entry align="left">
276           <para>group</para>
277         </entry>
278         <entry align="left">
279           <para>XID or None</para>
280         </entry>
281         <entry align="left">
282           <para>None</para>
283         </entry>
284       </row>
285       <row>
286         <entry align="left">
287           <para>trust-level</para>
288         </entry>
289         <entry align="left">
290           <para>{SecurityClientTrusted,</para>
291         </entry>
292       </row>
293       <row>
294         <entry align="left">
295           <para></para>
296         </entry>
297         <entry align="left">
298           <para>SecurityClientUntrusted}</para>
299         </entry>
300         <entry align="left">
301           <para>SecurityClientUntrusted</para>
302         </entry>
303       </row>
304       <row>
305         <entry align="left">
306           <para>event-mask</para>
307         </entry>
308         <entry align="left">
309           <para>SecurityAuthorizationRevoked,</para>
310         </entry>
311       </row>
312       <row rowsep="1">
313         <entry align="left">
314           <para></para>
315         </entry>
316         <entry align="left">
317           <para>or None</para>
318         </entry>
319         <entry align="left">
320           <para>None</para>
321         </entry>
322       </row>
323       <row>
324         <entry align="left">
325           <para></para>
326         </entry>
327       </row>
328       <row>
329         <entry align="left">
330           <para></para>
331         </entry>
332       </row>
333     </tbody>
334   </tgroup>
335 </informaltable>
336
337 <para>
338 timeout is the timeout period in seconds for this authorization. A
339 timeout value of zero means this authorization will never expire. For
340 non-zero timeout values, when timeout seconds have elapsed since the
341 last time that the authorization entered the state of having no
342 connections authorized by it, and if no new connections used the
343 authorization during that time, the authorization is automatically purged.
344 (Note that when an authorization is created, it enters the state of having no
345 connections authorized by it.) Subsequent connection attempts using that
346 authorization will fail. This is to facilitate "fire and forget" launching of
347 applications.
348 </para>
349
350 <para>
351 group is an application group ID as defined by the Application Group
352 extension, or None. Any other values will cause a Value error. When a
353 group is destroyed, all authorizations specifying that group are revoked
354 as described under the SecurityRevokeAuthorization request. The Application
355 Group extension attaches additional semantics to the group.
356 </para>
357
358 <para>
359 trust-level tells whether clients using the authorization are trusted or
360 untrusted. If trust-level is not one of the constants SecurityClientTrusted
361 or SecurityClientUntrusted, a Value error results.
362 </para>
363
364 <para>
365 event-mask defines which events the client is interested in for this
366 authorization.  When the authorization expires or is revoked if event-mask
367 contains SecurityAuthorizationRevoked a SecurityAuthorizationRevoked event
368 is reported to the client.
369 </para>
370
371 <para>
372 The SecurityAuthorizationRevoked event contains the following field:
373 </para>
374
375 <informaltable>
376   <tgroup cols="2">
377     <tbody>
378       <row rowsep="1">
379         <entry align="left">
380           <para></para>
381         </entry>
382       </row>
383       <row rowsep="1">
384         <entry align="left">
385           <para>Field</para>
386         </entry>
387         <entry align="left">
388           <para>Type</para>
389         </entry>
390       </row>
391       <row rowsep="1">
392         <entry align="left">
393           <para>authorization-id</para>
394         </entry>
395         <entry align="left">
396           <para>AUTHID</para>
397         </entry>
398       </row>
399       <row>
400         <entry align="left">
401           <para></para>
402         </entry>
403       </row>
404       <row>
405         <entry align="left">
406           <para></para>
407         </entry>
408       </row>
409     </tbody>
410   </tgroup>
411 </informaltable>
412
413 <para>
414 where authorization-id is the identification of the authorization that was
415 revoked.
416 </para>
417 <para>
418 If an invalid value-mask is specified, a Value error occurs.
419 </para>
420
421 <para>
422 The returned authorization-id is a non-zero value that uniquely identifies
423 this authorization for use in other requests. The value space for type
424 AUTHID is not required to be disjoint from values spaces of other core
425 X types, e.g. resource ids, atoms, visual ids, and keysyms. Thus, a given
426 numeric value might be both a valid AUTHID and a valid atom, for example.
427 </para>
428
429 <para>
430 authorization-data-return is the data that a client should use in some
431 authorization-method-specific way to make a connection with this
432 authorization. For "MIT-MAGIC-COOKIE-1," authorization-data-return should
433 be sent as the authorization-protocol-data in the connection setup message.
434 It is not required that other authorization methods use
435 authorization-data-return this way.
436 </para>
437
438 </sect1>
439
440 <sect1 id="securityrevokeauthorization">
441 <title>SecurityRevokeAuthorization</title>
442
443 <para>
444 This request deletes an authorization created by SecurityGenerateAuthorization.
445 </para>
446
447 <para>
448 SecurityRevokeAuthorization
449 </para>
450
451 <informaltable>
452   <tgroup cols="2">
453     <tbody>
454       <row>
455         <entry align="left">
456           <para><emphasis remap='I'>authorization-id</emphasis></para>
457         </entry>
458         <entry align="left">
459           <para>AUTHID</para>
460         </entry>
461       </row>
462       <row>
463         <entry align="left">
464           <para></para>
465         </entry>
466       </row>
467     </tbody>
468   </tgroup>
469 </informaltable>
470
471 <para>
472 Errors: <function>Authorization</function>
473 </para>
474
475 <para>
476 If authorization-id does not name a valid authorization, an Authorization
477 error occurs. Otherwise, this request kills all clients currently connected
478 using the authorization specified by authorization-id. The authorization is
479 deleted from the server's database, so future attempts by clients to connect
480 with this authorization will fail.
481 </para>
482
483 </sect1>
484 </chapter>
485
486 <chapter id="changes_to_core_requests">
487 <title>Changes to Core Requests</title>
488
489 <para>
490 A server supporting this extension modifies the handling of some core
491 requests in the following ways.
492 </para>
493 <sect1 id="resource_id_usage">
494 <title>Resource ID Usage</title>
495
496 <para>
497 If an untrusted client makes a request that specifies a resource ID that is
498 not owned by another untrusted client, a protocol error is sent to the
499 requesting client indicating that the specified resource does not exist.
500 The following exceptions apply. An untrusted client can:
501 </para>
502
503 <orderedlist>
504   <listitem>
505     <para>
506 use  the  QueryTree,  GetGeometry,  and  TranslateCoordinates  requests
507 without restriction.
508     </para>
509   </listitem>
510   <listitem>
511     <para>
512 use colormap IDs that are returned in the default-colormap field of its
513 connection setup information in any colormap requests.
514     </para>
515   </listitem>
516   <listitem>
517      <para>specify a root window as:</para>
518      <orderedlist>
519        <listitem>
520          <para>
521 the drawable field of CreatePixmap, CreateGC, and QueryBestSize.
522          </para>
523        </listitem>
524        <listitem>
525          <para>the parent field of CreateWindow.</para>
526        </listitem>
527        <listitem>
528          <para>
529 the window field of CreateColormap, ListProperties, and GetWindowAttributes.
530          </para>
531        </listitem>
532        <listitem>
533          <para>the grab-window or confine-to fields of GrabPointer.
534          </para>
535        </listitem>
536        <listitem>
537          <para>the grab-window field of UngrabButton.</para>
538        </listitem>
539        <listitem>
540          <para>
541 the destination of SendEvent, but only if all of the following are true.
542 (These conditions cover all the events that the ICCCM specifies with
543 a root window destination.)
544          </para>
545          <orderedlist>
546            <listitem>
547              <para>The propogate field of SendEvent is False.</para>
548            </listitem>
549            <listitem>
550              <para>
551 The   event-mask   field   of   SendEvent   is   ColormapChange,
552 StructureNotify, or the logical OR of SubstructureRedirect with
553 SubstructureNotify.
554              </para>
555            </listitem>
556            <listitem>
557              <para>
558 The event type being sent is UnmapNotify, ConfigureRequest, or
559 ClientMessage.
560              </para>
561            </listitem>
562          </orderedlist>
563        </listitem>
564        <listitem>
565          <para>
566 the window field of ChangeWindowAttributes, but only if the value-mask
567 contains only event-mask and the corresponding value is StructureNotify,
568 PropertyChange, or the logical OR of both.
569          </para>
570        </listitem>
571     </orderedlist>
572   </listitem>
573 </orderedlist>
574
575 <note>
576 <para>
577 ISSUE: are root window exceptions needed for these? WarpPointer, ReparentWindow
578 (parent), CirculateWindow, QueryPointer (emacs does this), GetMotionEvents.
579 </para>
580 </note>
581
582 </sect1>
583 <sect1 id="extension_security">
584 <title>Extension Security</title>
585
586 <para>
587 This extension introduces the notion of secure and insecure extensions. A
588 secure extension is believed to be safe to use by untrusted clients; that
589 is, there are no significant security concerns known that an untrusted
590 client could use to destroy, modify, or steal data of trusted clients. This
591 belief may be founded on a careful analysis of the extension protocol,
592 its implementation, and measures taken to "harden" the extension to close
593 security weaknesses. All extensions not considered secure are called
594 insecure. The implementation details of how an extension is identified as
595 secure or insecure are beyond the scope of this specification.
596 </para>
597
598 <para>
599 <function>ListExtensions</function> will only return names of secure
600 extensions to untrusted clients.
601 </para>
602
603 <para>
604 If an untrusted client uses <function>QueryExtension</function> on an
605 insecure extension that the server supports, the reply will have the
606 present field set to False and the major-opcode field set to zero to
607 indicate that the extension is not supported.
608 </para>
609
610 <para>
611 If an untrusted client successfully guesses the major opcode of an
612 insecure extension, attempts by it to execute requests with that major
613 opcode will fail with a Request error.
614 </para>
615
616 </sect1>
617
618 <sect1 id="keyboard_security">
619 <title>Keyboard Security</title>
620
621
622 <para>
623 The protocol interpretation changes in this section are intended to prevent
624 untrusted applications from stealing keyboard input that was meant for
625 trusted clients and to prevent them from interfering with the use of the
626 keyboard.
627 </para>
628
629 <para>
630 The behavior of some keyboard-related requests and events is modified when
631 the client is untrusted depending on certain server state at the time of
632 request execution or event generation. Specifically, if a hypothetical
633 keyboard event were generated given the current input focus, pointer
634 position, keyboard grab state, and window event selections, and if that
635 keyboard event would not be delivered to any untrusted client, the
636 following changes apply:
637 </para>
638
639 <orderedlist>
640   <listitem>
641     <para>
642 The bit vector representing the up/down state of the keys returned by
643 <function>QueryKeymap</function> and
644 <function>KeymapNotify</function> is all zeroes.
645     </para>
646   </listitem>
647   <listitem>
648     <para>GrabKeyboard returns a status of AlreadyGrabbed.</para>
649   </listitem>
650   <listitem>
651     <para>
652 <function>SetInputFocus</function> does nothing. Note that this means the
653 Globally Active
654 Input and WM_TAKE_FOCUS mechanisms specified in the ICCCM will
655 not work with untrusted clients.
656     </para>
657   </listitem>
658   <listitem>
659     <para>
660 Passive grabs established by GrabKey that would otherwise have activated
661 do not activate.
662     </para>
663   </listitem>
664 </orderedlist>
665
666 <para>
667 If an untrusted client attempts to use any of the following requests, the
668 only effect is that the client receives an Access error: SetModifierMapping,
669 ChangeKeyboardMapping, ChangeKeyboardControl.
670 </para>
671
672 <para>
673 If an InputOnly window owned by an untrusted client has a parent owned by a
674 trusted client, all attempts to map the window will be ignored. This includes
675 mapping attempts resulting from MapWindow, MapSubwindows, ReparentWindow,
676 and save-set processing.
677 </para>
678 <para>
679 However, if the parent of an InputOnly window owned by an untrusted client
680 is the root window, attempts to map that window will be performed as
681 expected. This is in line with the root window exceptions above.
682 </para>
683 </sect1>
684
685 <sect1 id="image_security">
686 <title>Image Security</title>
687
688 <para>
689 It should be impossible for an untrusted client to retrieve the image
690 contents of a trusted window unless a trusted client takes action to allow
691 this. We introduce the following defenses in support of this requirement.
692 </para>
693
694 <para>
695 The restrictions on resource ID usage listed above prevent untrusted clients
696 from using GetImage directly on windows not belonging to trusted clients.
697 </para>
698
699 <para>
700 If an untrusted client tries to set the background-pixmap attribute of an
701 untrusted window to None, the server will instead use a server-dependent
702 background which must be different than None.
703 </para>
704
705 <para>
706 The X protocol description of <function>GetImage</function> states that the
707 returned contents of regions of a window obscured by noninferior windows are
708 undefined if the window has no backing store. Some implementations return the
709 contents of the obscuring windows in these regions. When an untrusted client
710 uses <function>GetImage</function>, this behavior is forbidden; the server must
711 fill the obscured regions in the returned image with a server-dependent pattern.
712 </para>
713
714 <para>
715 If an untrusted window has trusted inferiors, their contents are vulnerable
716 to theft via <function>GetImage</function> on the untrusted parent, as well
717 as being vulnerable to destruction via drawing with subwindow-mode
718 IncludeInferiors on the untrusted parent. An untrusted window having trusted
719 inferiors can only occur at the request of a trusted client. It is expected
720 to be an unusual configuration.
721 </para>
722
723 </sect1>
724
725 <sect1 id="property_security">
726
727 <title>Property Security</title>
728
729 <para>
730 Unlike the other security provisions described in this document, security for
731 property access is not amenable to a fixed policy because properties are
732 used for inter-client communication in diverse ways and may contain data of
733 varying degrees of sensitivity. Therefore, we only list the possible
734 restrictions the server may decide to impose on use of properties on trusted
735 windows by untrusted clients. How the server chooses which restrictions from
736 this list to apply to a particular property access is implementation dependent
737   <footnote><para>
738 In the X Consortium server implementation, property access is controlled by
739 a configuration file; see the -sp option in the Xserver(1) manual page.
740   </para></footnote>.
741 </para>
742
743 <para>The X Protocol property requests are
744 <function>ChangeProperty</function>,
745 <function>GetProperty</function>,
746 <function>DeleteProperty</function>,
747 <function>RotateProperties</function>, and
748 <function>ListProperties</function>. For these requests, the server can
749 allow the request to execute normally (as if it had been issued by a
750 trusted client), ignore the request completely (as if it were a NoOperation),
751 or ignore the request except to send an Atom error to the client. Ignoring
752 a <function>ListProperties</function> request means replying that
753 the window has no properties. <function>ListProperties</function> may also
754 reply with a subset of the existing properties if the server is doing
755 property hiding; see below. An ignored <function>GetProperty</function>
756 request may reply that the property does not exist, or that it exists but
757 contains no data.
758 </para>
759
760 <para>
761 The server may decide to hide certain properties on certain windows from
762 untrusted clients
763   <footnote><para>
764 The X Consortium server implementation does not currently provide a way to
765 hide properties.
766   </para></footnote>.
767 If a property is to be hidden, it must be done consistently to avoid
768 confusing clients.  This means that for untrusted clients:
769 </para>
770
771 <itemizedlist>
772   <listitem>
773     <para>
774 That property should not be returned by
775 <function>ListProperties</function>.
776     </para>
777   </listitem>
778   <listitem>
779     <para>
780 <function>PropertyNotify</function> events should not be sent for that
781 property.</para>
782     </listitem>
783   <listitem>
784     <para>
785 <function>GetProperty</function> on that property should reply that the
786 property does not exist (the return type is None, the format and
787 bytes-after are zero, and the value is empty).
788     </para>
789   </listitem>
790 </itemizedlist>
791
792 <para>
793 For a property that the server is protecting but not hiding, consistency
794 must also be maintained:
795 </para>
796
797 <itemizedlist>
798   <listitem>
799     <para>
800 That property should be returned by <function>ListProperties</function>.
801     </para>
802   </listitem>
803   <listitem>
804     <para>
805 <function>PropertyNotify</function> events should be sent for that property.
806     </para>
807   </listitem>
808   <listitem>
809     <para>
810 <function>GetProperty</function> on that property should reply that the
811 property exists (if it really does) but the value is empty
812 (return type and format are their real values, and the "length of value"
813 field in the reply is zero).
814     </para>
815   </listitem>
816 </itemizedlist>
817
818 </sect1>
819
820 <sect1 id="miscellaneous_security">
821 <title>Miscellaneous Security</title>
822
823 <para>
824 If an untrusted client attempts to use
825 <function>ChangeHosts</function>,
826 <function>ListHosts</function>, or
827 <function>SetAccessControl</function>,
828 the only effect is that the client receives an Access error.
829 </para>
830
831 <para>
832 If an untrusted client attempts to use <function>ConvertSelection</function>
833 on a selection with a trusted selection owner window, the server generates
834 a SelectionNotify event to the requestor with property None.
835 </para>
836 </sect1>
837 </chapter>
838
839 <chapter id="new_authorization_method">
840 <title>New Authorization Method</title>
841
842 <para>
843 This extension includes a new authorization method named
844 "XC-QUERY-SECURITY-1".  Its purpose is to allow an external agent such as
845 the X firewall proxy to probe an X server to determine whether that server
846 meets certain security criteria without requiring the agent to have its
847 own authorization for that server. The agent may use the returned information
848 to make a decision. For example, the X firewall proxy may choose not to
849 forward client connections to servers that do not meet the criteria.
850 </para>
851
852 <para>
853 To use this authorization method, the client (or proxy) sends
854 "XC-QUERY-SECURITY-1" as the authorization-protocol-name in the initial
855 connection setup message. The authorization-protocol-data may be empty or
856 may contain additional security criteria desribed below. If the success
857 field of the server's reply is Authenticate, the server supports the
858 security extension, and the server meets all specified additional security
859 criteria. In this case, the client should resend the initial connection
860 setup message substituting the authorization protocol name and data
861 that should be used to authorize the connection. If the success field of the
862 server's reply is anything other than Authenticate, either the server does not
863 support the security extension, does not meet (or cannot determine if it
864 meets) all of the additional security criteria, or chooses for internal reasons
865 not to answer with Authenticate. In this case, the client should close the
866 connection.
867 </para>
868
869 <para>
870 If the authorization-protocol-data sent with "XC-QUERY-SECURITY-1" is not
871 empty, it specifies additional security criteria for the server to check, as
872 follows.
873 </para>
874
875 <para>
876 <function>authorization-protocol-data</function>
877 </para>
878
879 <informaltable>
880   <tgroup cols="2">
881     <tbody>
882       <row>
883         <entry align="left">
884           <para>policy-mask</para>
885         </entry>
886         <entry align="left">
887           <para>BITMASK</para>
888         </entry>
889       </row>
890       <row>
891         <entry align="left">
892           <para>policies</para>
893         </entry>
894         <entry align="left">
895           <para>LISTofSECURITYPOLICY</para>
896         </entry>
897       </row>
898       <row>
899         <entry align="left">
900           <para></para>
901         </entry>
902       </row>
903     </tbody>
904   </tgroup>
905 </informaltable>
906
907 <para>
908 The policy-mask field is any logical-OR combination of the constants
909 Extensions and SitePolicies. For each bit set in policy-mask, there is a
910 SECURITYPOLICY element in policies. The nth element in policies corresponds
911 to the nth 1-bit in policy-mask, counting upward from bit 0.
912 </para>
913
914 <para><function>SECURITYPOLICY</function></para>
915
916 <informaltable>
917   <tgroup cols="2">
918     <tbody>
919       <row>
920         <entry align="left">
921           <para>policy-type</para>
922         </entry>
923         <entry align="left">
924           <para>{Disallow, Permit}</para>
925         </entry>
926       </row>
927       <row>
928         <entry align="left">
929           <para>names</para>
930         </entry>
931         <entry align="left">
932           <para>LISTofSTR</para>
933         </entry>
934       </row>
935       <row>
936         <entry align="left">
937           <para></para>
938         </entry>
939       </row>
940     </tbody>
941   </tgroup>
942 </informaltable>
943
944 <para>
945 For a SECURITYPOLICY corresponding to policy-mask Extensions, if
946 policy-type is Disallow the server is required to consider as insecure
947 all extensions given in names.  No policy is specified for extensions
948 not listed in names. If policy-type is Permit the server may consider
949 only those extensions given in names to be secure; all other extensions
950 must be treated as insecure. If these constraints are not met, the server
951 should not return Authenticate in the success field of the reply.
952 Servers can but need not dynamically configure themselves in response
953 to an Extensions SECURITYPOLICY; a conforming server might simply compare
954 the policy with a compiled-in table of extensions and their security status.
955 </para>
956
957 <para>
958 For a SECURITYPOLICY corresponding to policy-mask SitePolicies, policy-type
959 Disallow means the server must not have been configured with any of the site
960 policies given in names. Policy-type Permit means the server must have
961 been configured with at least one of the site policies given in names. If
962 these constraints are not met, the server should not return Authenticate in
963 the success field of the reply.
964 </para>
965
966 <para>
967 SitePolicies provide a way to express new forms of security-relevant
968 information that could not be anticipated at the time of this writing.
969 For example, suppose the server is found to have a critical security defect.
970 When a fix is developed, a site policy string could be associated with the
971 fix. Servers with the fix would advertise that site policy, and the X
972 firewall proxy would specify that site policy in a SECURITYPOLICY with
973 policy-type Permit.
974 </para>
975
976 </chapter>
977
978 <chapter id="encoding">
979 <title>Encoding</title>
980
981 <para>
982 Please refer to the X11 Protocol Encoding document as this section
983 uses syntactic conventions and data types established there.
984 </para>
985
986 <para>
987 The name of this extension is "SECURITY".
988 </para>
989
990 <sect1 id="types">
991 <title>Types</title>
992 <para>
993 AUTHID: CARD32
994 </para>
995 </sect1>
996
997 <sect1 id="request_encoding">
998 <title>Request Encoding</title>
999
1000 <para>
1001 SecurityQueryVersion
1002 </para>
1003 <literallayout remap='FD'>
1004 1         CARD8         major-opcode
1005 1         0                minor-opcode
1006 2         2              request length
1007 2         CARD16        client-major-version
1008 2         CARD16        client-minor-version
1009 =>
1010 1         1     Reply
1011 1               unused
1012 2         CARD16    sequence number
1013 4         0     reply length
1014 2         CARD16    server-major-version
1015 2         CARD16    server-minor-version
1016 20                            unused
1017 </literallayout>
1018
1019 <para>
1020 <function>SecurityRevokeAuthorization</function>
1021 </para>
1022
1023 <literallayout remap='FD'>
1024 1         CARD8          major-opcode
1025 1         2                  minor-opcode
1026 2         2                  request length
1027 4         AUTHID         authorization-id
1028 </literallayout>
1029
1030 <para>
1031 SecurityGenerateAuthorization
1032 </para>
1033
1034 <literallayout remap='FD'>
1035 1         CARD8              major-opcode
1036 1         1                      minor-opcode
1037 2         3 + (m+n+3)/4 + s  request length
1038 2         CARD16             m, number of bytes in authorization protocol name
1039 2         CARD16             n, number of bytes in authorization data
1040 m        STRING8             authorization protocol name
1041 n         STRING8            authorization protocol data
1042 p                                  unused, p=pad(m+n)
1043 4         BITMASK          value-mask (has s bits set to 1)
1044        #x00000001          timeout
1045        #x00000002          trust-level
1046        #x00000004          group
1047        #x00000008          event-mask
1048 4s        LISTofVALUE       value-list
1049 </literallayout>
1050
1051 <para>
1052 VALUES
1053 </para>
1054 <literallayout remap='FD'>
1055 4      CARD32        timeout
1056 4                          trust-level
1057        0                   SecurityClientTrusted
1058        1                   SecurityClientUntrusted
1059 4      XID              group
1060 0                          None
1061 4      CARD32           event-mask
1062        #x00000001       SecurityAuthorizationRevoked
1063 =>
1064 1         1               Reply
1065 1                         unused
1066 2         CARD16     sequence number
1067 4         (q+3)/4        reply length
1068 4         AUTHID       authorization-id
1069 2         CARD16       data-length
1070 18                        unused
1071 q         STRING8      authorization-data-return
1072 r                         unused, r=pad(q)
1073 </literallayout>
1074
1075 </sect1>
1076
1077 <sect1 id="event_encoding">
1078 <title>Event Encoding</title>
1079 <para>
1080 <function>SecurityAuthorizationRevoked</function>
1081 </para>
1082
1083 <literallayout remap='FD'>
1084 1         0+extension event base        code
1085 1                                                 unused
1086 2         CARD16                             sequence number
1087 4         AUTHID                             authorization id
1088 24                                                unused
1089 </literallayout>
1090
1091 </sect1>
1092
1093 <sect1 id="authorization_method_encoding">
1094 <title>Authorization Method Encoding</title>
1095
1096 <para>
1097 For authorization-protocol-name "XC-QUERY-SECURITY-1", the
1098 authorization-protocol-data is interpreted as follows:
1099 </para>
1100
1101 <para>
1102 <function>authorization-protocol-data</function>
1103 </para>
1104 <literallayout remap='FD'>
1105 1         BITMASK                              policy-mask
1106           #x00000001            Extensions
1107           #x00000002            SitePolicies
1108 m        LISTofSECURITYPOLICY                  policies
1109 </literallayout>
1110
1111 <para>
1112 <function>SECURITYPOLICY</function>
1113 </para>
1114
1115 <literallayout remap='FD'>
1116 1                                                             policy-type
1117           0                         Permit
1118           1                         Disallow
1119 1         CARD8                                          number of STRs in names
1120 n         LISTofSTR                                      names
1121 </literallayout>
1122
1123 <para>
1124 LISTofSTR has the same encoding as in the X protocol: each STR is a single
1125 byte length, followed by that many characters, and there is no padding or
1126 termination between STRs.
1127 </para>
1128 </sect1>
1129
1130 </chapter>
1131 <chapter id="c_language_binding">
1132 <title>C Language Binding</title>
1133
1134 <para>
1135 The header for this extension is &lt;X11/extensions/security.h&gt;. All
1136 identifier names provided by this header begin with XSecurity.
1137 </para>
1138
1139 <para>
1140 All functions that have return type Status will return nonzero for
1141 success and zero for failure.
1142 </para>
1143
1144 <funcsynopsis>
1145 <funcprototype>
1146   <funcdef>Status <function>XSecurityQueryExtension</function></funcdef>
1147     <paramdef>Display <parameter> *dpy</parameter></paramdef>
1148     <paramdef>int <parameter> *major_version_return</parameter></paramdef>
1149     <paramdef>int <parameter> *minor_version_return</parameter></paramdef>
1150 </funcprototype>
1151 </funcsynopsis>
1152
1153 <para>
1154 <function>XSecurityQueryExtension</function> sets major_version_return and
1155 minor_version_return to the major and minor Security protocol version
1156 supported by the server. If the Security library is compatible with the
1157 version returned by the server, it returns nonzero. If dpy does not support
1158 the Security extension, or if there was an error during communication with
1159 the server, or if the server and library protocol versions are incompatible,
1160 it returns zero. No other XSecurity functions may be called before this
1161 function. If a client violates this rule, the effects of all subsequent
1162 XSecurity calls that it makes are undefined.
1163 </para>
1164
1165 <funcsynopsis>
1166 <funcprototype>
1167   <funcdef>Xauth *<function>XSecurityAllocXauth</function></funcdef>
1168     <paramdef><parameter>void</parameter></paramdef>
1169 </funcprototype>
1170 </funcsynopsis>
1171 <para>
1172 In order to provide for future evolution, Xauth structures are used to
1173 pass and return authorization data, and the library provides ways to
1174 allocate and deallocate them.
1175 </para>
1176
1177 <para>
1178 <function>XSecurityAllocXauth</function> must be used to allocate the
1179 Xauth structure that is passed to
1180 <function>XSecurityGenerateAuthorization</function>.
1181 </para>
1182
1183 <para>
1184 For the purposes of the Security extension, the Xauth structure has
1185 the following fields:
1186 </para>
1187
1188 <informaltable>
1189   <tgroup cols="3">
1190     <tbody>
1191       <row rowsep="1">
1192         <entry align="left">
1193           <para></para>
1194         </entry>
1195       </row>
1196       <row rowsep="1">
1197         <entry align="left">
1198           <para>Type</para>
1199         </entry>
1200         <entry align="left">
1201           <para>Field name</para>
1202         </entry>
1203         <entry align="left">
1204           <para>Description</para>
1205         </entry>
1206       </row>
1207       <row>
1208         <entry align="left">
1209           <para>unsigned short</para>
1210         </entry>
1211         <entry align="left">
1212           <para>name_length</para>
1213         </entry>
1214         <entry align="left">
1215           <para>number of bytes in name</para>
1216         </entry>
1217       </row>
1218       <row>
1219         <entry align="left">
1220           <para>char *</para>
1221         </entry>
1222         <entry align="left">
1223           <para>name</para>
1224         </entry>
1225         <entry align="left">
1226           <para>authorization protocol name</para>
1227         </entry>
1228       </row>
1229       <row>
1230         <entry align="left">
1231           <para>unsigned short</para>
1232         </entry>
1233         <entry align="left">
1234           <para>data_length</para>
1235         </entry>
1236         <entry align="left">
1237           <para>number of bytes in data</para>
1238         </entry>
1239       </row>
1240       <row rowsep="1">
1241         <entry align="left">
1242           <para>char *</para>
1243         </entry>
1244         <entry align="left">
1245            <para>data</para>
1246         </entry>
1247         <entry align="left">
1248           <para>authorization protocol data</para>
1249         </entry>
1250      </row>
1251      <row>
1252        <entry align="left">
1253          <para></para>
1254        </entry>
1255      </row>
1256      <row>
1257        <entry align="left">
1258          <para></para>
1259        </entry>
1260      </row>
1261    </tbody>
1262   </tgroup>
1263 </informaltable>
1264 <para>
1265 The Xauth structure returned by this function is initialized as follows:
1266 name_length and data_length are zero, and name and data are NULL.
1267 </para>
1268
1269 <funcsynopsis>
1270 <funcprototype>
1271   <funcdef>void <function>XSecurityFreeXauth</function></funcdef>
1272     <paramdef>Xauth<parameter> *auth</parameter></paramdef>
1273 </funcprototype>
1274 </funcsynopsis>
1275
1276 <para>
1277 <function>XSecurityFreeXauth</function> must be used to free Xauth
1278 structures allocated by
1279 <function>XSecurityAllocXauth</function> or returned by
1280 <function>XSecurityGenerateAuthorization</function>. It is the
1281 caller's responsibility to fill in the name and data fields of Xauth structures
1282 allocated with <function>XSecurityAllocXauth</function>, so this function
1283 will not attempt to free them. In contrast, all storage associated with
1284 Xauth structures returned from
1285 <function>XSecurityGenerateAuthorization</function> will be freed by this
1286 function, including the name and data fields.
1287 </para>
1288
1289
1290 <funcsynopsis>
1291 <funcprototype>
1292   <funcdef>Bool <function>XSecurityRevokeAuthorization</function></funcdef>
1293     <paramdef>Display<parameter> *dpy</parameter></paramdef>
1294     <paramdef>XSecurityAuthorization<parameter> auth_id</parameter></paramdef>
1295 </funcprototype>
1296 </funcsynopsis>
1297
1298 <para>
1299 <function>XSecurityRevokeAuthorization</function> deletes the authorization
1300 specified by auth_id, which must be a value returned in the auth_id_return
1301 parameter of <function>XSecurityGenerateAuthorization</function>. All
1302 clients that connected with that authorization are be killed. Subsequently,
1303 clients that attempt to connect using that authorization will be refused.
1304 </para>
1305
1306
1307 <funcsynopsis>
1308 <funcprototype>
1309   <funcdef>Xauth *<function>XSecurityGenerateAuthorization</function></funcdef>
1310     <paramdef>Display<parameter> *dpy</parameter></paramdef>
1311     <paramdef>Xauth<parameter> *auth_in</parameter></paramdef>
1312     <paramdef>unsigned long<parameter> valuemask</parameter></paramdef>
1313     <paramdef>XSecurityAutorizationAttributes <parameter> *attributes</parameter></paramdef>
1314     <paramdef>XSecurityAutorization<parameter> *auth_id_return</parameter></paramdef>
1315 </funcprototype>
1316 </funcsynopsis>
1317
1318 <para>
1319 <function>XSecurityGenerateAuthorization</function> creates a new
1320 authorization with the specified attributes. The auth_in argument must be
1321 allocated by <function>XSecurityAllocXauth</function>. The
1322 name and name_length fields of auth_in should be initialized to the
1323 authorization protocol name and its length in characters respectively.
1324 If there is authorization data, the data and data_length fields of
1325 auth_in should be initialized to the data and its length in characters
1326 respectivley. The library does not assume that name and data are
1327 null-terminated strings. The auth_in argument must be freed with
1328 <function>XSecurityFreeXauth</function>.
1329 </para>
1330
1331 <para>
1332 The XSecurityAuthorizationAttributes structure has the following fields:
1333 </para>
1334
1335 <informaltable>
1336   <tgroup cols="3">
1337     <tbody>
1338       <row rowsep="1">
1339         <entry align="left">
1340           <para></para>
1341         </entry>
1342       </row>
1343       <row rowsep="1">
1344         <entry align="left">
1345           <para>Type</para>
1346         </entry>
1347         <entry align="left">
1348           <para>Field name</para>
1349         </entry>
1350         <entry align="left">
1351           <para>Mask</para>
1352         </entry>
1353       </row>
1354       <row>
1355         <entry align="left">
1356           <para>unsigned int</para>
1357         </entry>
1358         <entry align="left">
1359           <para>trust_level</para>
1360         </entry>
1361         <entry align="left">
1362           <para>XSecurityTrustLevel</para>
1363         </entry>
1364       </row>
1365       <row>
1366         <entry align="left">
1367           <para>unsigned int</para>
1368         </entry>
1369         <entry align="left">
1370           <para>timeout</para>
1371         </entry>
1372         <entry align="left">
1373           <para>XSecurityTimeout</para>
1374         </entry>
1375       </row>
1376       <row>
1377         <entry align="left">
1378           <para>XID</para>
1379         </entry>
1380         <entry align="left">
1381           <para>group</para>
1382         </entry>
1383         <entry align="left">
1384           <para>XSecurityGroup</para>
1385         </entry>
1386       </row>
1387       <row rowsep="1">
1388         <entry align="left">
1389           <para>long</para>
1390         </entry>
1391         <entry align="left">
1392           <para>event_mask</para>
1393         </entry>
1394         <entry align="left">
1395           <para>XSecurityEventMask</para>
1396         </entry>
1397       </row>
1398       <row>
1399         <entry align="left">
1400           <para></para>
1401         </entry>
1402       </row>
1403       <row>
1404         <entry align="left">
1405           <para></para>
1406         </entry>
1407       </row>
1408     </tbody>
1409   </tgroup>
1410 </informaltable>
1411
1412 <para>
1413 These correspond to the trust-level, timeout, group, and event-mask
1414 described in the SecurityGenerateAuthorization protocol request. The
1415 caller can fill in values for any subset of these attributes. The valuemask
1416 argument must be the bitwise OR of the symbols listed in the Mask column
1417 for all supplied attributes. The event_mask attribute can be None,
1418 XSecurityAuthorizationRevokedMask, or XSecurityAllEventMasks. In this
1419 revision of the protocol specification XSecurityAllEventMasks is equivalent
1420 to XSecurityAuthorizationRevokedMask. If the caller does not need to
1421 specify any attributes, the attributes argument can be NULL, and the
1422 valuemask argument must be zero.
1423 </para>
1424 <para>
1425 If the function fails, NULL is returned and auth_id_return is filled in
1426 with zero.  Otherwise, a pointer to an Xauth structure is returned. The name
1427 and name_length fields of the returned Xauth structure will be copies of the
1428 name that was passed in, and the data and data_length fields will be set to
1429 the authorization data returned by the server. The caller should not assume
1430 that name and data are null-terminated strings. If no authorization data was
1431 returned by the server, the data and data_length fields will be set to NULL
1432 and zero repectively. The returned Xauth structure must be freed with
1433 <function>XSecurityFreeXauth</function>; the caller should not use any other
1434 means free the structure or any of its components. The auth_id_return
1435 argument will be filled in with the non-zero authorization id of the created
1436 authorization.
1437 </para>
1438
1439 <para>
1440 The XSecurityAuthorizationRevokedEvent structure has the following fields:
1441 </para>
1442
1443 <informaltable>
1444   <tgroup cols="3">
1445     <tbody>
1446       <row rowsep="1">
1447         <entry align="left">
1448           <para></para>
1449         </entry>
1450       </row>
1451       <row rowsep="1">
1452         <entry align="left">
1453           <para>Type</para>
1454         </entry>
1455         <entry align="left">
1456           <para>Field name</para>
1457         </entry>
1458         <entry align="left">
1459           <para>Description</para>
1460         </entry>
1461
1462       </row>
1463       <row>
1464         <entry align="left">
1465           <para>int</para>
1466         </entry>
1467         <entry align="left">
1468           <para>type</para>
1469         </entry>
1470         <entry align="left">
1471           <para>event base + XSecurityAuthorizationRevoked</para>
1472         </entry>
1473       </row>
1474       <row>
1475         <entry align="left">
1476           <para>unsigned long</para>
1477         </entry>
1478         <entry align="left">
1479           <para>serial</para>
1480         </entry>
1481         <entry align="left">
1482           <para># of last request processed by server</para>
1483         </entry>
1484       </row>
1485       <row>
1486         <entry align="left">
1487           <para>Bool</para>
1488         </entry>
1489         <entry align="left">
1490           <para>send_event</para>
1491         </entry>
1492         <entry align="left">
1493           <para>true if this came from SendEvent</para>
1494         </entry>
1495       </row>
1496       <row>
1497         <entry align="left">
1498           <para>Display*</para>
1499         </entry>
1500         <entry align="left">
1501           <para>display</para>
1502         </entry>
1503         <entry align="left">
1504           <para>Display the event was read from</para>
1505         </entry>
1506       </row>
1507       <row rowsep="1">
1508         <entry align="left">
1509           <para>XSecurityAuthorization</para>
1510         </entry>
1511         <entry align="left">
1512           <para>auth_id</para>
1513         </entry>
1514         <entry align="left">
1515           <para>revoked authorization id</para>
1516         </entry>
1517       </row>
1518       <row>
1519         <entry align="left">
1520           <para></para>
1521         </entry>
1522       </row>
1523       <row>
1524         <entry align="left">
1525           <para></para>
1526         </entry>
1527       </row>
1528     </tbody>
1529   </tgroup>
1530 </informaltable>
1531 </chapter>
1532 </book>