Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle Cygwin / Git Bash sockets forwarding on Windows
This is used to forward ssh-agent connection to Git Bash' ssh-agent. Here is the explanation of what is required to connect to a cygwin / git bash unix domain socket on Windows: - Port parsing: - Git Bash' unix sockets requires connecting to the port whose number is in the socket file along with a cookie. - The socket file contains something like `!<socket >63488 s 44693F4F-E2572CA5-537862AB-248DFDEF` - The port here is `63488` and the cookie is `44693F4F-E2572CA5-537862AB-248DFDEF`. - So I retrieve the port and cookie using a regex and convert it to a number. - If the file content does not match the regex, I assume this is a GPG socket and use the existing code to parse it. - When I have the port and the cookie, I connect to `127.0.0.1:<port>`, then I do the following handshake. - Cygwin / Git Bash socket Handshake: - The handshake consists in: - the client must send the cookie as 16 raw bytes - The cookie is formatted in the socket file as 4 32 bits hex integers. They must be send to the ssh-agent server in little endian as 16 raw bytes (this means according to the above example: `0x4F 0x3F 0x69 0x44 0xA5 0x72 ...`). - the server send back the same 16 bytes if the cookie is valid, else closes the connection (so the client must skip these 16 bytes, as done in `skipHeader`) - the client must send pid and user id and user effective id information in a 12 bytes packet - I set the pid to a real value from process.pid, but ssh-agent ignores it - user id and user effective id are both set to 0 - the server send back the same information, but about the server, I just ignore these 12 bytes too in `skipHeader`; this is a function that just skip the handshake data). As the server send back data in the handshake phase (16 + 12 bytes), I need to skip them through the use of `skipHeader`. Then actual data transfer can take place. See also: https://stackoverflow.com/questions/23086038/what-mechanism-is-used-by-msys-cygwin-to-emulate-unix-domain-sockets https://github.com/abourget/secrets-bridge/blob/094959a1553943e0727f6524289e12e8aab697bf/pkg/agentfwd/agentconn_windows.go#L15 Fix: #62
- Loading branch information