-
Notifications
You must be signed in to change notification settings - Fork 150
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
Fix Windows compatibility issues and AGE support #436
Conversation
e4e383a
to
7eaee93
Compare
Should I add a Windows build GitHub Workflow to this? I'm not too familiar with Workflows, but it shouldn't be too difficult. The question is whether CI for Windows is a priority, and if it should be part of this PR or separate. |
Many thanks for the contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial review - please take a look below:
libagent/ssh/__init__.py
Outdated
@@ -154,12 +197,15 @@ def run_server(conn, command, sock_path, debug, timeout): | |||
ret = 0 | |||
try: | |||
handler = protocol.Handler(conn=conn, debug=debug) | |||
with serve(handler=handler, sock_path=sock_path, | |||
timeout=timeout) as env: | |||
serve_platform = serve_win if sys.platform == 'win32' else serve_unix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serve_platform = serve_win if sys.platform == 'win32' else serve_unix | |
serve_func = serve_win if sys.platform == 'win32' else serve_unix |
Also the CI seems to fail - please take a look: |
7eaee93
to
1227770
Compare
I believe I fixed the CI. But without a Dockerfile to run Python Tox, I can't test it locally. I'm also poking a bit into GPG support. I've already found a few issues that only appear on Windows, e.g. needing to URL-decode paths returned by There's also a mild issue with it that I'm unsure how to handle, and could influence all the tools. And that's the location of Also, it's a slight issue for me to test, since I don't have a hardware device that requires an on-computer PIN entry. |
Please fix the code style issues:
https://github.com/romanz/trezor-agent/actions/runs/6123995379/job/16624649832?pr=436 |
@Pandapip1 could you please help testing this PR? |
Sure! Are there any build instructions I can follow? For now, I'm making a program using USB/IP that mostly implements the smart card USB interface for use with the Trezor. But if you could get this working, that'd be better! |
1227770
to
ba4d39e
Compare
Currently not working (On Windows):
|
ba4d39e
to
96cf4fd
Compare
Improved Ctrl+C behavior. Before, running the GPG agent directly with no client would cause it to freeze, and be uninterruptible. Also improved behavior of named pipe so it remains open while waiting for a connection, and closes instantly on Ctrl+C. |
c26e285
to
a280f02
Compare
Fixed, but didn't test, GPG subkey registration. |
a280f02
to
254da47
Compare
More linting |
67204d9
to
e0cdad8
Compare
isorted |
9f898f0
to
b0a793d
Compare
More lints, and minor fixes. Hopefully CI finally passes this time. |
b0a793d
to
e16d321
Compare
Okay, after playing around with GPG for a day, I made some minor changes, and updated the docs a lot. And also, GPG is awesome, and I don't know why people are trying to find replacements for it. I also have a pretty good idea of how to implement an But adding it to this PR would be too many features in one PR. So, as soon as all the fixes are done and this PR is merged, I'll work on that feature. |
It's OK to rebase without signing the commit, if you prefer. |
Good catch - if |
73d9484
to
d0d0c83
Compare
libagent/util.py
Outdated
Does not add quotes. This allows appending multiple strings inside the quotes. | ||
""" | ||
if sys.platform == 'win32': | ||
return in_str.translate({37: '%%', 34: '\"\"'}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: prefer using a single char key for readability:
>>> 'abcba'.translate(str.maketrans({'a': 'AA', 'b': 'BB'}))
'AABBcBBAA'
(here and below)
libagent/ssh/__init__.py
Outdated
@@ -258,8 +295,8 @@ def main(device_type): | |||
|
|||
public_keys = None | |||
filename = None | |||
if args.identity.startswith('/'): | |||
filename = args.identity | |||
if args.identity.startswith('/') or args.identity.startswith('file:'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please define FILE_PREFIX = 'file:'
and use it and len(FILE_PREFIX)
here:
libagent/ssh/__init__.py
Outdated
log.error('running in foreground mode requires specifying %s', SOCK_TYPE_PATH) | ||
sys.exit(1) | ||
elif sys.platform == 'win32': | ||
suffix = random.choices(string.ascii_letters, k=10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure - will any ASCII letter suffix work on Windows?
Maybe it's simpler/safer to use something like os.urandom(N).hex()
here? or even https://docs.python.org/3/library/tempfile.html#tempfile.mkstemp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mkstemp
is not applicable because it will try to create and open the file, which can't be done for a pipe address. mktemp
will also try to check for the file's existence, which may or may not work for a pipe address, and is deprecated.
libagent/ssh/__init__.py
Outdated
try: | ||
os.unlink(self.file.name) | ||
except OSError: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a log.warning
here (in case file removal fails).
libagent/gpg/__init__.py
Outdated
check_call(['mkdir', '-p', homedir]) | ||
check_call(['chmod', '700', homedir]) | ||
# Prepare the key before making any changes | ||
key_id, public_key = export_public_key(device_type, args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
key_id, public_key = export_public_key(device_type, args) | |
key_id, public_key_bytes = export_public_key(device_type, args) |
@Pandapip1 Please take a look at https://github.com/romanz/trezor-agent/blob/d0d0c83638f29d631a0e56f6e15e87d30fe9ea9a/doc/README-Windows.md |
LGTM (reviewed most of the code - except |
39f7b62
to
93d0ce8
Compare
Already rebased as a merge. Was fairly simple to do
It does, used. Fixed pydocs. According to |
93d0ce8
to
48c549d
Compare
Okay, now it should lint. Crosses fingers |
48c549d
to
98c6db9
Compare
Drat. Seems like the |
No wait. The issue is with the test. It uses a mock subprocess |
Okay, how do I fix it? If I change the mock process, it's going to be a trivial test. If I use a real call, would GPG be available in the testing environment? Alternately, I can just remove the test. |
98c6db9
to
e471108
Compare
Okay, for now I'm attempting with a real process. If it goes well, great. If not, I'm going to need help with this. |
e471108
to
6d5fa84
Compare
Okay, that went better than I was expecting. Corrected the test. Should work now. |
6d5fa84
to
fa6d80e
Compare
Optimized the GPG init so it doesn't create files that don't need to stay there. |
Not meaning to rush anyone, but CI has finally passed, I've applied the suggested fixes (where applicable), and while there's a small mountain of fixes I want to add, none of them are specific to Windows, i.e. they should not be part of this PR. So, what is the next step? Waiting for testers? Reviewing the last few bits of code added? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, and many thanks for the work!
@SlugFiller Thank you for running with this and actually preserving my contribution. I was obviously out of my comfort zone. GPG support is coming too? Nice work! |
@gtbuchanan While I ended up changing a lot, your contribution was a huge factor in being able to make this PR, or at the very least, make it this quickly (Less than a week from conception to merge). At a bare minimum, having a working named pipes with overlapped io implementation in pywin32 I could reference, got the hard part out of the way. |
Thank you both! I already made a workaround involving WSL, but if it works natively that's even better (and presumably better-supported!) |
Builds on top of #362. Fixed parts that weren't working correctly, ensured it builds on Python 3.11 without errors, fixed issues with AGE, and added Windows-specific documentation.
Only thing missing is GPG support. However, I couldn't find a user-friendly non-CygWin GPG client for Windows. And I've never used GPG in the past. This makes it difficult to test, debug, or even just document GPG usage.
All other tools are confirmed to work, and appropriate Windows-specific tooling for them has been documented.