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

Support Windows? #185

Open
a3135134 opened this issue Apr 19, 2020 · 13 comments
Open

Support Windows? #185

a3135134 opened this issue Apr 19, 2020 · 13 comments

Comments

@a3135134
Copy link

I use win 10 and install this python module. However, it raises ModuleNotFoundError: No module named '_crypt' . It seems _crypt only work on Unix/Linux, so this library also only support Linux?

@jlusiardi
Copy link
Owner

Hi,
This module should also work under windows, but only for IP based accessories, no Bluetooth LE support. I have a few questions:

  • how did you install the module?
  • which version did you install?
  • where there any errors during install?
  • what is the exact output when it tries to load _crypt? I am not aware the _crypt module is loaded directly by the modules code.

@a3135134
Copy link
Author

I used cmd " pip install homekit". When I try python -m homekit.discover, here's the log:

Traceback (most recent call last):
File "E:\Python3\lib\runpy.py", line 183, in run_module_as_main
mod_name, mod_spec, code = get_module_details(mod_name, Error)
File "E:\Python3\lib\runpy.py", line 109, in get_module_details
import(pkg_name)
File "E:\Python3\lib\site-packages\homekit_init
.py", line 26, in
from homekit.controller import Controller
File "E:\Python3\lib\site-packages\homekit\controller_init
.py", line 21, in
from homekit.controller.controller import Controller
File "E:\Python3\lib\site-packages\homekit\controller\controller.py", line 26, in
from homekit.protocol.tlv import TLV
File "E:\Python3\lib\site-packages\homekit\protocol_init.py", line 31, in
from homekit.crypto import chacha20_aead_decrypt, chacha20_aead_encrypt, SrpClient
File "E:\Python3\lib\site-packages\homekit\crypto_init.py", line 22, in
from homekit.crypto.srp import SrpClient, SrpServer
File "E:\Python3\lib\site-packages\homekit\crypto\srp.py", line 23, in
import crypt
File "E:\Python3\lib\crypt.py", line 3, in
import _crypt
ModuleNotFoundError: No module named '_crypt'

@jlusiardi
Copy link
Owner

Mh interesting point, looks like the crypt module is not available on windows (https://docs.python.org/3/library/crypt.html). Because only crypt.mksalt is needed, we might reimplement that?

@a3135134
Copy link
Author

Yes. Might choose a cross-platform python lib.

@Jc2k
Copy link
Collaborator

Jc2k commented Apr 20, 2020

It looks like crypt.mksalt is justed used to generate random 16-byte numbers needed by Srp as salt and keys. One of the crypto libraries we already depend on (cryptography) has some advice in that case:

https://cryptography.io/en/latest/random-numbers/

It should be fine to replace mksalt with:

int.from_bytes(os.urandom(16), byteorder="big")

On python 3.6 and later an option would be:

int.from_bytes(secrets.token_bytes(16), byteorder="big")

No new libraries required.

@jlusiardi
Copy link
Owner

@Jc2k sounds good, this should be the solution.

@jlusiardi
Copy link
Owner

Hey @a3135134,

can you try with branch fix_185_homekit_on_windows? I removed the dependency to crypt in that.

@a3135134
Copy link
Author

a3135134 commented Apr 20, 2020

Hey @a3135134,

can you try with branch fix_185_homekit_on_windows? I removed the dependency to crypt in that.

I placed the homekit directory into python lib.

python -m homekit.discover
Traceback (most recent call last):
File "E:\Python3\lib\runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, Error)
File "E:\Python3\lib\runpy.py", line 109, in get_module_details
import(pkg_name)
File "E:\Python3\lib\site-packages\homekit_init
.py", line 26, in
from homekit.controller import Controller
File "E:\Python3\lib\site-packages\homekit\controller_init
.py", line 21, in
from homekit.controller.controller import Controller
File "E:\Python3\lib\site-packages\homekit\controller\controller.py", line 23, in
import tlv8
ModuleNotFoundError: No module named 'tlv8'

I tried pip install tlv8. Here's a different error
File "E:\Python3\lib\site-packages\zeroconf.py", line 1817, in init
self._listen_socket.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, _value)
OSError: [WinError 10042]

@jlusiardi
Copy link
Owner

Fixed the issue with tlv8.

Is there nothing behind the OSError: [WinError 10042]?

@jlusiardi jlusiardi reopened this Apr 20, 2020
@jlusiardi
Copy link
Owner

close was not intended?

@a3135134
Copy link
Author

Fixed the issue with tlv8.

Is there nothing behind the OSError: [WinError 10042]?

I think this is another problem. I'll have a check first
OSError: [WinError 10042] An unknown, invalid, or unsupported option or level specified in the getsockopt or setsockopt call.

@jlusiardi jlusiardi reopened this Apr 21, 2020
@jlusiardi
Copy link
Owner

So I was able to install homekit_python on a win 10 VM.

  1. Python 3.8.2 and git via https://chocolatey.org/
  2. create virtual env: py.exe -m venv venv
  3. Allow script execution: Set-ExecutionPolicy Bypass -Scope Process -Force;
  4. activate virtual env: .\venv\Scripts\activate
  5. Clone Repo: &'C:\Program Files\Git\bin\git.exe' clone https://github.com/jlusiardi/homekit_python.git
  6. cd homekit_python
  7. Checkout branch: &'C:\Program Files\Git\bin\git.exe' checkout fix_185_homekit_on_windows
  8. Install C++-Buildtools from Microsoft (https://visualstudio.microsoft.com/de/visual-cpp-build-tools/, required for install ed25519 python package)
  9. Install the branch: pip3 install .[IP]
  10. Use py.exe -m homekit.discover to check for homekit accessories. This wants to access network, so you might want to allow that.

Results: One of my accessories is found

Name: Koogeek-P1-770D90._hap._tcp.local.
Url: http_impl://192.168.178.200:80
Configuration number (c#): 2
Feature Flags (ff): Supports HAP Pairing (Flag: 1)
Device ID (id): 44:AF:68:9E:5D:17
Model Name (md): P1EU
Protocol Version (pv): 1.1
State Number (s#): 1
Status Flags (sf): Accessory has been paired. (Flag: 0)
Category Identifier (ci): Outlet (Id: 7)

@jlusiardi
Copy link
Owner

@a3135134 does this work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants