File: _checks.py

package info (click to toggle)
solo1-cli 0.1.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 464 kB
  • sloc: python: 2,168; makefile: 36
file content (39 lines) | stat: -rw-r--r-- 1,052 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import ctypes
import os
import platform

LINUX_ROOT_WARNING = """THIS COMMAND SHOULD NOT BE RUN AS ROOT!

Please install udev rules and run `solo` as regular user (without sudo).
For more information, see: https://docs.solokeys.io/solo/udev"""

WINDOWS_CTAP_WARNING = """Try running `solo` with administrator privileges!
FIDO CTAP access is restricted on Windows 10 version 1903 and higher."""


def windows_ctap_restriction():
    win_ver = platform.sys.getwindowsversion()
    return (
        # Windows 10 1903 and higher
        win_ver.major == 10
        and win_ver.build >= 18362
        and ctypes.windll.shell32.IsUserAnAdmin() != 1
    )


def windows_checks():
    if windows_ctap_restriction():
        print(WINDOWS_CTAP_WARNING)


def linux_checks():
    if os.environ.get("ALLOW_ROOT") is None and os.geteuid() == 0:
        print(LINUX_ROOT_WARNING)


def init_checks():
    os_family = platform.sys.platform
    if os_family.startswith("linux"):
        linux_checks()
    elif os_family.startswith("win32"):
        windows_checks()