Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication is reading 2 bytes at a time #128

Closed
bdraco opened this issue Oct 30, 2022 · 3 comments · Fixed by #131
Closed

Authentication is reading 2 bytes at a time #128

bdraco opened this issue Oct 30, 2022 · 3 comments · Fixed by #131
Labels
bug Something isn't working

Comments

@bdraco
Copy link
Member

bdraco commented Oct 30, 2022

connect(48, {sa_family=AF_UNIX, sun_path="/var/run/dbus/system_bus_socket"}, 34) = 0
ioctl(48, FIONBIO, [1])                 = 0
getpid()                                = 61
sendto(48, "\0", 1, 0, NULL, 0)         = 1
getuid()                                = 0
sendto(48, "AUTH EXTERNAL 30\r\n", 18, 0, NULL, 0) = 18
recvfrom(48, "OK", 2, 0, NULL, NULL)    = 2
recvfrom(48, " 2", 2, 0, NULL, NULL)    = 2
recvfrom(48, "7e", 2, 0, NULL, NULL)    = 2
recvfrom(48, "cd", 2, 0, NULL, NULL)    = 2
recvfrom(48, "1c", 2, 0, NULL, NULL)    = 2
recvfrom(48, "33", 2, 0, NULL, NULL)    = 2
recvfrom(48, "de", 2, 0, NULL, NULL)    = 2
recvfrom(48, "69", 2, 0, NULL, NULL)    = 2
recvfrom(48, "bc", 2, 0, NULL, NULL)    = 2
recvfrom(48, "a6", 2, 0, NULL, NULL)    = 2
recvfrom(48, "1b", 2, 0, NULL, NULL)    = 2
recvfrom(48, "ca", 2, 0, NULL, NULL)    = 2
recvfrom(48, "f9", 2, 0, NULL, NULL)    = 2
recvfrom(48, "1b", 2, 0, NULL, NULL)    = 2
recvfrom(48, "e3", 2, 0, NULL, NULL)    = 2
recvfrom(48, "76", 2, 0, NULL, NULL)    = 2
recvfrom(48, "fc", 2, 0, NULL, NULL)    = 2
recvfrom(48, "6\r", 2, 0, NULL, NULL)   = 2
recvfrom(48, "\n", 2, 0, NULL, NULL)    = 1
sendto(48, "NEGOTIATE_UNIX_FD\r\n", 19, 0, NULL, 0) = 19
recvfrom(48, "AG", 2, 0, NULL, NULL)    = 2
recvfrom(48, "RE", 2, 0, NULL, NULL)    = 2
recvfrom(48, "E_", 2, 0, NULL, NULL)    = 2
recvfrom(48, "UN", 2, 0, NULL, NULL)    = 2
recvfrom(48, "IX", 2, 0, NULL, NULL)    = 2
recvfrom(48, "_F", 2, 0, NULL, NULL)    = 2
recvfrom(48, "D\r", 2, 0, NULL, NULL)   = 2
recvfrom(48, "\n", 2, 0, NULL, NULL)    = 1
sendto(48, "BEGIN\r\n", 7, 0, NULL, 0)  = 7

@bdraco bdraco added the bug Something isn't working label Oct 30, 2022
@bdraco
Copy link
Member Author

bdraco commented Oct 31, 2022


    async def _auth_readline(self) -> str:
        buf = b""
        while buf[-2:] != b"\r\n":
            buf += await self._loop.sock_recv(self._sock, 2)
        return buf[:-2].decode()

@bdraco
Copy link
Member Author

bdraco commented Oct 31, 2022

we can actually mis align the buffer here since we should only read up to 1 if we have b"BEGIN\r"

@bdraco
Copy link
Member Author

bdraco commented Oct 31, 2022

So we should read 1024, and then when we expect BEGIN\r\n we need to only read the missing bytes

bdraco added a commit that referenced this issue Oct 31, 2022
We now try to read a whole line at a time
since there is no risk of reading too far
ahead given that the spec says:

The first octet received by the server after the \r\n of the BEGIN command from the client must be the first octet of the authenticated/encrypted stream of D-Bus messages.

Unlike all other commands, the server does not reply to the BEGIN command with an authentication command of its own. After the \r\n of the reply to the command before BEGIN, the next octet received by the client must be the first octet of the authenticated/encrypted stream of D-Bus messages.

fixes #128
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant