Skip to content

Commit

Permalink
Fix: use ~/.gnupg when /etc/openvas/gnupg is not available
Browse files Browse the repository at this point in the history
Instead of just using GOS defaults `/etc/openvas/gnupg` check if the
directory exists and when not use `$HOME/.gnupg` instead.

If both are not available print a warning that the env variable
GNUPGHOME should be set but stick with the failing `$HOME/.gnupg` to
prevent None checking.

Fixes #765
  • Loading branch information
nichtsfrei committed Sep 9, 2022
1 parent 9d0bd4e commit 97fe15b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion ospd_openvas/gpg_sha_verifier.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
import hashlib
import os
import logging
from pathlib import Path
from typing import Callable, Dict, Optional

from dataclasses import dataclass
from gnupg import GPG

logger = logging.getLogger(__name__)
OPENVAS_GPG_HOME = "/etc/openvas/gnupg"


def __determine_default_gpg_home() -> Path:
gos_default = Path(OPENVAS_GPG_HOME)
if gos_default.exists():
return gos_default
user_default = Path.home() / ".gnupg"
if not user_default.exists():
logger.warning(
"No GnuPG home found; "
"please verify setup and set the GNUPGHOME variable if necessary"
)
return user_default


def __default_gpg_home() -> GPG:
"""
__defaultGpgHome tries to load the variable 'GNUPGHOME' or to guess it
"""
manual = os.getenv("GNUPGHOME")

home = Path(manual) if manual else Path(OPENVAS_GPG_HOME)
home = Path(manual) if manual else __determine_default_gpg_home()
logger.debug("Using %s as GnuPG home.", home)
return GPG(gnupghome=f"{home.absolute()}")


Expand Down

0 comments on commit 97fe15b

Please sign in to comment.