diff --git a/build-helper.sh b/build-helper.sh index e8d81c765..c8d990998 100755 --- a/build-helper.sh +++ b/build-helper.sh @@ -40,7 +40,7 @@ VENV="../$OUTPUT/helper-license-venv" rm -rf $VENV poetry run python -m venv $VENV $VENV/bin/pip install --upgrade pip wheel -$VENV/bin/pip install dist/authenticator_helper-0.1.0-py3-none-any.whl pip-licenses +$VENV/bin/pip install dist/authenticator_helper-0.2.0-py3-none-any.whl pip-licenses $VENV/bin/pip-licenses --format=json --no-license-path --with-license-file --ignore-packages authenticator-helper zxing-cpp --output-file ../assets/licenses/helper.json cd .. diff --git a/helper/helper/qr.py b/helper/helper/qr.py index 1109f71f6..5292e1027 100644 --- a/helper/helper/qr.py +++ b/helper/helper/qr.py @@ -12,66 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mss import zxingcpp import base64 import io -import os -import sys -import subprocess # nosec -import tempfile -from mss.exception import ScreenShotError +import pyscreenshot as ImageGrab +from pyscreenshot import FailedBackendError from PIL import Image -import numpy.core.multiarray # noqa - - -def _capture_screen(): - try: - with mss.mss() as sct: - monitor = sct.monitors[0] # 0 is the special "all monitors" value. - sct_img = sct.grab(monitor) # mss format - return Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX") - except ScreenShotError: - # One common error is that mss doesn't work with Wayland - if sys.platform.startswith("linux"): - # Try calling screenshot tools, with original library path - env = dict(os.environ) - lp = env.get("LD_LIBRARY_PATH_ORIG") - if lp is not None: - env["LD_LIBRARY_PATH"] = lp - else: - env.pop("LD_LIBRARY_PATH", None) - fd, fname = tempfile.mkstemp(suffix=".png") - - try: - # Try using gnome-screenshot - rc = subprocess.call( # nosec - ["gnome-screenshot", "-f", fname], env=env - ) - if rc == 0: - return Image.open(fname) - except FileNotFoundError: - # Try using spectacle (KDE) - try: - rc = subprocess.call( # nosec - ["spectacle", "-b", "-n", "-o", fname], env=env - ) - if rc == 0: - return Image.open(fname) - except FileNotFoundError: - pass # Fall through to ValueError - finally: - os.unlink(fname) - raise ValueError("Unable to capture screenshot") - def scan_qr(image_data=None): + img = None if image_data: msg = base64.b64decode(image_data) buf = io.BytesIO(msg) img = Image.open(buf) else: - img = _capture_screen() + try: + img = ImageGrab.grab() + except FailedBackendError: + raise ValueError("Unable to capture screenshot") result = zxingcpp.read_barcode(img) if result and result.valid: diff --git a/helper/poetry.lock b/helper/poetry.lock index 3a5e30d59..6b0751af9 100755 --- a/helper/poetry.lock +++ b/helper/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand. +# This file is automatically @generated by Poetry and should not be changed by hand. [[package]] name = "altgraph" @@ -158,6 +158,30 @@ test = ["iso8601", "pretend", "pytest (>=6.2.0)", "pytest-benchmark", "pytest-co test-randomorder = ["pytest-randomly"] tox = ["tox"] +[[package]] +name = "easyprocess" +version = "1.1" +description = "Easy to use Python subprocess interface." +category = "main" +optional = false +python-versions = "*" +files = [ + {file = "EasyProcess-1.1-py3-none-any.whl", hash = "sha256:82eed523a0a5eb12a81fa4eacd9f342caeb3f900eb4b798740e6696ad07e63f9"}, + {file = "EasyProcess-1.1.tar.gz", hash = "sha256:885898302a57aab948973e8b5d32a4229392b9fb2d986ab1d4ffd590e5ba90ec"}, +] + +[[package]] +name = "entrypoint2" +version = "1.1" +description = "easy to use command-line interface for python modules" +category = "main" +optional = false +python-versions = "*" +files = [ + {file = "entrypoint2-1.1-py2.py3-none-any.whl", hash = "sha256:eeb8c327bdb65cdd1668c023a6b110b7e3d1a046fb05e043861ebd9264b3a257"}, + {file = "entrypoint2-1.1.tar.gz", hash = "sha256:fc0b7fe7b21acdab47a585ab9407ca7e5c4f96cb6888575db6b0ceb91f0e105a"}, +] + [[package]] name = "exceptiongroup" version = "1.1.1" @@ -193,14 +217,14 @@ pcsc = ["pyscard (>=1.9,<3)"] [[package]] name = "importlib-metadata" -version = "6.4.1" +version = "6.5.0" description = "Read metadata from Python packages" category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "importlib_metadata-6.4.1-py3-none-any.whl", hash = "sha256:63ace321e24167d12fbb176b6015f4dbe06868c54a2af4f15849586afb9027fd"}, - {file = "importlib_metadata-6.4.1.tar.gz", hash = "sha256:eb1a7933041f0f85c94cd130258df3fb0dec060ad8c1c9318892ef4192c47ce1"}, + {file = "importlib_metadata-6.5.0-py3-none-any.whl", hash = "sha256:03ba783c3a2c69d751b109fc0c94a62c51f581b3d6acf8ed1331b6d5729321ff"}, + {file = "importlib_metadata-6.5.0.tar.gz", hash = "sha256:7a8bdf1bc3a726297f5cfbc999e6e7ff6b4fa41b26bba4afc580448624460045"}, ] [package.dependencies] @@ -331,14 +355,14 @@ files = [ [[package]] name = "mss" -version = "8.0.3" +version = "9.0.1" description = "An ultra fast cross-platform multiple screenshots module in pure python using ctypes." category = "main" optional = false python-versions = ">=3.8" files = [ - {file = "mss-8.0.3-py3-none-any.whl", hash = "sha256:87c1eda213dab83431013ca98ee7217e536439f28446b979bb38d8f7af5c7d34"}, - {file = "mss-8.0.3.tar.gz", hash = "sha256:07dc0602e325434e867621f257a8ec6ea14bdffd00bfa554a69bef554af7f524"}, + {file = "mss-9.0.1-py3-none-any.whl", hash = "sha256:7ee44db7ab14cbea6a3eb63813c57d677a109ca5979d3b76046e4bddd3ca1a0b"}, + {file = "mss-9.0.1.tar.gz", hash = "sha256:6eb7b9008cf27428811fa33aeb35f3334db81e3f7cc2dd49ec7c6e5a94b39f12"}, ] [[package]] @@ -578,6 +602,24 @@ files = [ gui = ["wxPython"] pyro = ["Pyro"] +[[package]] +name = "pyscreenshot" +version = "3.1" +description = "python screenshot" +category = "main" +optional = false +python-versions = ">=3.4" +files = [ + {file = "pyscreenshot-3.1-py3-none-any.whl", hash = "sha256:73d406d41a0977125bdfd2f6488f0caf1394e84d1d4c1065d5e8b1400b307096"}, + {file = "pyscreenshot-3.1.tar.gz", hash = "sha256:8c0e93f0aef66a6bfe55a86abfced6bd396ae4b4f6cc1e36f04a28ad2625594d"}, +] + +[package.dependencies] +EasyProcess = "*" +entrypoint2 = "*" +jeepney = {version = "*", markers = "python_version > \"3.4\" and platform_system == \"Linux\""} +mss = {version = "*", markers = "python_version > \"3.4\""} + [[package]] name = "pytest" version = "7.3.1" @@ -655,14 +697,14 @@ jeepney = ">=0.6" [[package]] name = "setuptools" -version = "67.6.1" +version = "67.7.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "setuptools-67.6.1-py3-none-any.whl", hash = "sha256:e728ca814a823bf7bf60162daf9db95b93d532948c4c0bea762ce62f60189078"}, - {file = "setuptools-67.6.1.tar.gz", hash = "sha256:257de92a9d50a60b8e22abfcbb771571fde0dbf3ec234463212027a4eeecbe9a"}, + {file = "setuptools-67.7.0-py3-none-any.whl", hash = "sha256:888be97fde8cc3afd60f7784e678fa29ee13c4e5362daa7104a93bba33646c50"}, + {file = "setuptools-67.7.0.tar.gz", hash = "sha256:b7e53a01c6c654d26d2999ee033d8c6125e5fa55f03b7b193f937ae7ac999f22"}, ] [package.extras] @@ -750,4 +792,4 @@ numpy = "*" [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "f0fc2e7d5ef423dc8b247ab6b968a63c331e78bd74bd72020b634f6823a74e3d" +content-hash = "806c628e645eff951152db31a1f0e931e2758508c02420ae83674be03b4d58d6" diff --git a/helper/pyproject.toml b/helper/pyproject.toml index 296b3ff62..e2e24daea 100644 --- a/helper/pyproject.toml +++ b/helper/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "authenticator-helper" -version = "0.1.0" +version = "0.2.0" description = "Yubico Authenticator Helper" authors = ["Dain Nilsson "] packages = [ @@ -11,9 +11,9 @@ packages = [ [tool.poetry.dependencies] python = "^3.8" yubikey-manager = "5.1.0" -mss = "^8.0.3" zxing-cpp = "^2.0.0" Pillow = "^9.5.0" +pyscreenshot = "^3.1" [tool.poetry.dev-dependencies] pyinstaller = {version = "^5.10.1", python = "<3.12"}