config: Make the OS keyring optional.

This commit is contained in:
Damir Jelić 2019-05-23 13:32:57 +02:00
parent 32c17421e2
commit e597969a21
4 changed files with 31 additions and 10 deletions

View File

@ -10,3 +10,4 @@ ListenPort = 8009
Proxy = http://localhost:8080 Proxy = http://localhost:8080
SSL = False SSL = False
IgnoreVerification = False IgnoreVerification = False
UseKeyring = True

View File

@ -46,6 +46,11 @@ A boolean that decides if device verification should be enabled. If this is True
devices will be marked as ignored automatically and encryption keys will be devices will be marked as ignored automatically and encryption keys will be
shared with them, if this is False the user needs to verify, blacklist or ignore shared with them, if this is False the user needs to verify, blacklist or ignore
devices manually before messages can be sent to a room. Defaults to "False". devices manually before messages can be sent to a room. Defaults to "False".
.It Cm UseKeyring
This option configures if a proxy instance should use the OS keyring to store
its own access tokens. The access tokens are required for the daemon to resume
operation. If this is set to "No", access tokens are stored in the pantalaimon
database in plaintext. Defaults to "Yes".
.El .El
.Pp .Pp
Aditional to the homeserver section a special section with the name Aditional to the homeserver section a special section with the name
@ -56,6 +61,7 @@ can be used to configure the following values for all homeservers:
.Cm Proxy , .Cm Proxy ,
.Cm SSL .Cm SSL
.Cm IgnoreVerification .Cm IgnoreVerification
.Cm UseKeyring
.Pp .Pp
The The
.Cm Default .Cm Default

View File

@ -33,6 +33,7 @@ class PanConfigParser(configparser.ConfigParser):
"ListenPort": "8009", "ListenPort": "8009",
"LogLevel": "warnig", "LogLevel": "warnig",
"Notifications": "on", "Notifications": "on",
"UseKeyring": "yes",
}, },
converters={ converters={
"address": parse_address, "address": parse_address,
@ -110,6 +111,7 @@ class ServerConfig:
proxy = attr.ib(type=str, default="") proxy = attr.ib(type=str, default="")
ssl = attr.ib(type=bool, default=True) ssl = attr.ib(type=bool, default=True)
ignore_verification = attr.ib(type=bool, default=False) ignore_verification = attr.ib(type=bool, default=False)
keyring = attr.ib(type=bool, default=True)
@attr.s @attr.s
@ -164,6 +166,7 @@ class PanConfig:
listen_port = section.getint("ListenPort") listen_port = section.getint("ListenPort")
ssl = section.getboolean("SSL") ssl = section.getboolean("SSL")
ignore_verification = section.getboolean("IgnoreVerification") ignore_verification = section.getboolean("IgnoreVerification")
keyring = section.getboolean("UseKeyring")
proxy = section.geturl("Proxy") proxy = section.geturl("Proxy")
listen_tuple = (listen_address, listen_port) listen_tuple = (listen_address, listen_port)
@ -181,7 +184,8 @@ class PanConfig:
listen_port, listen_port,
proxy, proxy,
ssl, ssl,
ignore_verification ignore_verification,
keyring
) )
self.servers[section_name] = server_conf self.servers[section_name] = server_conf

View File

@ -78,10 +78,13 @@ class ProxyDaemon:
accounts = self.store.load_users(self.name) accounts = self.store.load_users(self.name)
for user_id, device_id in accounts: for user_id, device_id in accounts:
token = keyring.get_password( if self.conf.keyring:
"pantalaimon", token = keyring.get_password(
f"{user_id}-{device_id}-token" "pantalaimon",
) f"{user_id}-{device_id}-token"
)
else:
token = self.store.load_access_token(user_id, device_id)
if not token: if not token:
logger.warn(f"Not restoring client for {user_id} {device_id}, " logger.warn(f"Not restoring client for {user_id} {device_id}, "
@ -527,11 +530,18 @@ class ProxyDaemon:
self.pan_clients[user_id] = pan_client self.pan_clients[user_id] = pan_client
keyring.set_password( if self.conf.keyring:
"pantalaimon", keyring.set_password(
f"{user_id}-{pan_client.device_id}-token", "pantalaimon",
pan_client.access_token f"{user_id}-{pan_client.device_id}-token",
) pan_client.access_token
)
else:
self.store.save_access_token(
user_id,
pan_client.device_id,
pan_client.access_token
)
pan_client.start_loop() pan_client.start_loop()