简体   繁体   English

x11授权如何工作? (麻省理工学院魔术曲奇)

[英]How does x11 authorization works? (MIT Magic Cookie)

I am interested in an in depth answer explaining how exactly does X11 authorization works and especially MIT Magic Cookies. 我对深入的答案感兴趣,该答案解释了X11授权(特别是MIT Magic Cookies)的工作原理。

I understand that what it actually does is to forbid access to everyone else except the user that is logged in, also there are some control mechanisms that control whether a client application can connect to an Xdisplay server or not. 我知道它的实际作用是禁止访问除登录用户之外的其他所有用户,还有一些控制机制可以控制客户端应用程序是否可以连接到Xdisplay服务器。

I also found that there are five standard access control mechanisms and they can be categorized in three main categories: 我还发现有五种标准访问控制机制,它们可以分为三大类:

  1. Access based on host 基于主机的访问
  2. Access based on cookie 基于Cookie的访问
  3. Access based on user 基于用户的访问

But from this point and on I don't really understand the way these work and what ways they exactly use in order to do the authorizations. 但是从现在开始,我还不太了解这些工作的方式以及它们用于执行授权的确切方式。

Well, first of all there is a file ~/.Xauthority on the machine. 好吧,首先在机器上有一个〜/ .Xauthority文件。 Notice that (usually on machine with GUI) wrong permissions of this file, can cause a login screen loop... (took me hours to understand that). 请注意,(通常在具有GUI的计算机上)此文件的错误权限会导致登录屏幕循环...(花了我几个小时来理解)。

As you mentioned there are 5 mechanisms: 正如您提到的,有5种机制:

  1. Host access: the server has host access list (if a network address exists in this list, the connection is permitted). 主机访问:服务器具有主机访问列表(如果此列表中存在网络地址,则允许连接)。 the list is managed using xhost command. 该列表是使用xhost命令管理的。 NOTE: this doesn't allow more than a single connection simultaneously. 注意:这不允许同时进行多个连接。 I don't know more about this method because I don't really used it. 我对此方法一无所知,因为我并未真正使用它。 but you can see man Xserver GRANTING ACCESS section :) 但是您可以看到man Xserver GRANTING ACCESS部分:)

  2. MIT-magic-cookie-1: Generating 128bit of key ("cookie"), storing it in ~/.Xauthority (or where XAUTHORITY envvar points to). MIT-magic-cookie-1:生成128位密钥(“ cookie”),并将其存储在〜/ .Xauthority中(或XAUTHORITY envvar指向的位置)。 The client sends it to server plain ! 客户端将其发送到服务器平原 the server checks whether it has a copy of this "cookie" and if so, the connection is permitted. 服务器检查它是否具有此“ cookie”的副本,如果有,则允许连接。 the key is generated by DMX. 密钥由DMX生成。

  3. XDM-authorization-1: Again, there is a key stored in ~/.Xauthority. XDM-authorization-1:同样,〜/ .Xauthority中存储了一个密钥。 this key consists 2 parts- 56bit DES encryption key and 64bits of random data used as the authenticator. 该密钥由2部分组成-56位DES加密密钥和64位随机数据​​用作身份验证器。 When you connect to the server the client generate 192bits of data: ctime combined with 48bits identifier (for tcp/ip: ip address+port, for local connections it's the PID and 32 bit unique id). 当您连接到服务器时,客户端生成192bits的数据:ctime与48bits标识符组合在一起(对于tcp / ip:ip address + port,对于本地连接,它是PID和32位唯一ID)。 the DES key is used to encrypt the data and then it is sent to server. DES密钥用于加密数据,然后将其发送到服务器。 the server validate the user by decrypting it then validating the 64bits authenticator and additional data. 服务器通过解密来验证用户,然后验证64位身份验证器和其他数据。

  4. sun-des-1: it uses asymmetric encryption, the server has a public key which he uses to decrypt incomming requests. sun-des-1:它使用非对称加密,服务器具有一个公用密钥,供他用来解密传入的请求。 it also uses the "host list". 它还使用“主机列表”。 This require some additional mechanisms in the network, I don't have such network so again, I don't understand this mechanism well. 这需要网络中的一些其他机制,我再也没有这样的网络,所以我对这种机制不太了解。

  5. server interpreted: It can be implemented in so many ways... but in general, the client send 2 string to server. 服务器解释:它可以通过多种方式实现...但是通常,客户端向服务器发送2个字符串。 The second string is the user entry (such as username) and the first string is the entry type (such as localuser). 第二个字符串是用户条目(例如,用户名),第一个字符串是条目类型(例如,localuser)。

NOTE: the 2nd, 3rd and 4th mechanisms store the keys inside ~/.Xauthority therefore anyone who has access to this file, can connect to the server pretending to be "you". 注意:第2,第3和第4种机制将密钥存储在〜/ .Xauthority中,因此,有权访问此文件的任何人都可以连接到假装为“您”的服务器。

xauth command can parse Xauthority file and extract the interesting values. xauth命令可以解析Xauthority文件并提取有趣的值。

$ xauth 
Using authority file /home/ME/.Xauthority
xauth> list        
ME/unix:10  MIT-MAGIC-COOKIE-1  5e443c146376d0bdadfd712bfe7654be
ME/unix:0  MIT-MAGIC-COOKIE-1  c48ddba801384dce3aaaa9d442931ea12
xauth> info
Authority file:       /home/ME/.Xauthority
File new:             no
File locked:          no
Number of entries:    2
Changes honored:      yes
Changes made:         no
Current input:        (stdin):2
xauth> 
  • The data is changed.... 数据已更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM