Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#
# # test if secretstorage dbus is working
# import secretstorage # @Reimport @UnresolvedImport
# bus = secretstorage.dbus_init()
# _ = list(secretstorage.get_all_collections(bus))
# # if yes, import it
# import keyring.backends.SecretService # @Reimport
# ss_keyring = keyring.backends.SecretService.Keyring()
# if ss_keyring.priority:
# import keyring # @Reimport
# # if priority is not 0, we set it as keyring system
# keyring.set_keyring(ss_keyring)
import keyring.backends.SecretService # @Reimport
import keyring # @Reimport
# config.logger.debug("controller: keyring.get_keyring() %s",keyring.get_keyring())
keyring.set_keyring(keyring.backends.SecretService.Keyring())
# config.logger.debug("controller: keyring.get_keyring() %s",keyring.get_keyring())
except Exception as e:
import sys
_, _, exc_tb = sys.exc_info()
config.logger.error("controller: Linux keyring Exception %s (line %s)",e,exc_tb.tb_lineno)
pass
#config.logger.debug("keyring: %s",str(keyring.get_keyring()))
except Exception as e:
import sys # @Reimport
_, _, exc_tb = sys.exc_info()
config.logger.error("controller: keyring Exception %s (line %s)",e,exc_tb.tb_lineno)
import winkerberos
except ImportError:
pprint("Requires module winkerberos")
sys.exit()
try:
import ntlm_auth.ntlm
except ImportError:
pprint("Requires module ntlm-auth")
sys.exit()
try:
import keyring
import keyring.backends.Windows
keyring.set_keyring(keyring.backends.Windows.WinVaultKeyring())
except ImportError:
pprint("Requires module keyring")
sys.exit()
# Python 2.x vs 3.x support
try:
import configparser
import http.server as httpserver
import socketserver
import urllib.parse as urlparse
import winreg
except ImportError:
import ConfigParser as configparser
import SimpleHTTPServer as httpserver
import SocketServer as socketserver
import urlparse
from .exceptions import (
MissingKeyError,
InvalidWifError,
WalletExists,
WalletLocked,
WrongMasterPasswordException,
NoWalletException,
OfflineHasNoRPCException,
AccountDoesNotExistsException,
)
from beemapi.exceptions import NoAccessApi
from beemgraphenebase.py23 import py23_bytes
from .storage import configStorage as config
try:
import keyring
if not isinstance(keyring.get_keyring(), keyring.backends.fail.Keyring):
KEYRING_AVAILABLE = True
else:
KEYRING_AVAILABLE = False
except ImportError:
KEYRING_AVAILABLE = False
log = logging.getLogger(__name__)
class Wallet(object):
""" The wallet is meant to maintain access to private keys for
your accounts. It either uses manually provided private keys
or uses a SQLite database managed by storage.py.
:param SteemNodeRPC rpc: RPC connection to a Steem node
:param keys: Predefine the wif keys to shortcut the
from maestral.config.base import get_conf_path
from maestral.sync.oauth_implicit import DropboxOAuth2FlowImplicit
from maestral.sync.errors import CONNECTION_ERRORS, DropboxAuthError
logger = logging.getLogger(__name__)
APP_KEY = "2jmbq42w7vof78h"
if IS_MACOS_BUNDLE:
import keyring.backends.OS_X
keyring.set_keyring(keyring.backends.OS_X.Keyring())
else:
# get preferred keyring backends for platform, excluding the chainer backend
all_keyrings = keyring.backend.get_all_keyring()
preferred_kreyrings = [k for k in all_keyrings if not isinstance(k, keyring.backends.chainer.ChainerBackend)]
keyring.set_keyring(max(preferred_kreyrings, key=lambda x: x.priority))
class OAuth2Session(object):
"""
OAuth2Session provides OAuth2 login and token store.
"""
TOKEN_FILE = osp.join(get_conf_path(SUBFOLDER), "o2_store.txt") # before v0.2.0
oAuth2FlowResult = None
Success = 0
InvalidToken = 1
ConnectionFailed = 2
CONFIG.update(loaded_config)
if args.config_string:
# Load the config string
loaded_config = json.loads(args.config_string)
CONFIG.update(loaded_config)
need_save = setup_config(CONFIG)
if need_save and args.config_file and args.update_config:
with open(args.config_file, "w") as f:
json.dump(CONFIG, f, indent=4, sort_keys=True)
if not ("xmpp_username" in CONFIG and "xmpp_host" in CONFIG):
raise ValueError("At least 'xmpp_username' and 'xmpp_host' must be "
"specified in config file or string")
keyring.set_keyring(keyring.backends.file.PlaintextKeyring())
save_password = False
if not args.update_config:
if "xmpp_password" in CONFIG:
# password is present in config file. No need to look
# for other options store password in keyring
temp = CONFIG["xmpp_password"]
save_password = True
# we need to store it in keyring because there is no way
# to distinguish between environments where password is
# always present in config file and otherwise. So even though
# config with password is going to be used always, the keyring
# might prompt for password for keyring on first run
else:
# Try to retrieve password from keyring
temp = keyring.get_password("ipop", CONFIG["xmpp_username"])
# Try to request valid password from user
def KeyringAvailable(self):
"""
determine if keyring module and an implementation is available for secure password storage
"""
try:
# Linux systems should use keyring only if it comes with the distro, otherwise chances are small
# that keyring works at all
if not platform.system() in ["Windows", "Darwin"]:
# keyring and secretstorage have to be importable
import keyring, secretstorage
if ("SecretService") in dir(keyring.backends) and not (keyring.get_keyring() is None):
return True
else:
# safety first - if not yet available disable it
#if not self.__dict__.has_key("use_system_keyring"):
if not 'use_system_keyring' in self.__dict__.keys():
self.use_system_keyring = False
# only import keyring lib if configured to do so
# necessary to avoid Windows crashes like https://github.com/HenriWahl/Nagstamon/issues/97
if self.use_system_keyring == True:
# hint for packaging: nagstamon.spec always have to match module path
# keyring has to be bound to object to be used later
import keyring
return not (keyring.get_keyring() is None)
else:
return False
except:
# only import keyring lib if configured to do so
# necessary to avoid Windows crashes like https://github.com/HenriWahl/Nagstamon/issues/97
if self.use_system_keyring is True:
# hint for packaging: nagstamon.spec always have to match module path
# keyring has to be bound to object to be used later
import keyring
return not (keyring.get_keyring() is None)
else:
return False
elif KEYRING:
# keyring and secretstorage have to be importable
import keyring
# import secretstorage module as dependency of keyring -
# if not available keyring won't work
import secretstorage
if ("SecretService") in dir(keyring.backends) and not (keyring.get_keyring() is None):
return True
else:
return False
else:
# apparently an Ubuntu KDE session which has problems with keyring
return False
except Exception:
import traceback
traceback.print_exc(file=sys.stdout)
return False
elide_string,
)
logger = logging.getLogger(__name__)
CONFIG_NAME = os.environ.get("MAESTRAL_CONFIG", "maestral")
# TODO: move this to sync.utils
if IS_MACOS_BUNDLE:
import keyring.backends.OS_X
keyring.set_keyring(keyring.backends.OS_X.Keyring())
else:
# get preferred keyring backends for platform, excluding the chainer backend
all_keyrings = keyring.backend.get_all_keyring()
preferred_kreyrings = [k for k in all_keyrings if not isinstance(k, keyring.backends.chainer.ChainerBackend)]
keyring.set_keyring(max(preferred_kreyrings, key=lambda x: x.priority))
# noinspection PyTypeChecker,PyArgumentList
class MaestralGuiApp(QtWidgets.QSystemTrayIcon):
"""A Qt GUI for the Maestral daemon."""
mdbx = None
_started = False
_context_menu_visible = False
PAUSE_TEXT = "Pause Syncing"
RESUME_TEXT = "Resume Syncing"