Compare commits

...

2 Commits

Author SHA1 Message Date
Kevin F
cd3a7cd7b2 Added identity generation 2022-10-22 06:22:29 +00:00
Kevin F
24e0157e15 Updated dockerfile 2022-10-22 06:22:05 +00:00
5 changed files with 115 additions and 20 deletions

View File

@ -1,4 +1,4 @@
FROM python:3.7 FROM python:3.10
EXPOSE 8080 EXPOSE 8080
USER root USER root
@ -15,7 +15,7 @@ RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen locale-gen
ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8
ADD ./requirements.txt /app/requirements.txt ADD ./requirements-x86-all-plugins.txt /app/requirements.txt
RUN pip3 install --require-hashes -r requirements.txt RUN pip3 install --require-hashes -r requirements.txt
#Add Onionr source #Add Onionr source
@ -28,4 +28,4 @@ RUN chmod g=u -R /app
USER 1000 USER 1000
ENV HOME=/app ENV HOME=/app
CMD ["bash", "./run-onionr-node.sh"] CMD ["bash", "./onionr.sh", "start"]

View File

@ -75,6 +75,7 @@ cffi==1.15.1 \
--hash=sha256:fcd131dd944808b5bdb38e6f5b53013c5aa4f334c5cad0c72742f6eba4b73db0 --hash=sha256:fcd131dd944808b5bdb38e6f5b53013c5aa4f334c5cad0c72742f6eba4b73db0
# via # via
# -r static-data/official-plugins/wot/requirements.in # -r static-data/official-plugins/wot/requirements.in
# cryptography
# pynacl # pynacl
cheroot==8.6.0 \ cheroot==8.6.0 \
--hash=sha256:366adf6e7cac9555486c2d1be6297993022eff6f8c4655c1443268cca3f08e25 \ --hash=sha256:366adf6e7cac9555486c2d1be6297993022eff6f8c4655c1443268cca3f08e25 \
@ -84,6 +85,34 @@ cherrypy==18.8.0 \
--hash=sha256:9b48cfba8a2f16d5b6419cc657e6d51db005ba35c5e3824e4728bb03bbc7ef9b \ --hash=sha256:9b48cfba8a2f16d5b6419cc657e6d51db005ba35c5e3824e4728bb03bbc7ef9b \
--hash=sha256:b56097025dc78a76a59db551b3a82871c6b3a0107b80b12ff759e4c0b3b947ce --hash=sha256:b56097025dc78a76a59db551b3a82871c6b3a0107b80b12ff759e4c0b3b947ce
# via -r static-data/official-plugins/rpc/requirements.in # via -r static-data/official-plugins/rpc/requirements.in
cryptography==38.0.1 \
--hash=sha256:0297ffc478bdd237f5ca3a7dc96fc0d315670bfa099c04dc3a4a2172008a405a \
--hash=sha256:10d1f29d6292fc95acb597bacefd5b9e812099d75a6469004fd38ba5471a977f \
--hash=sha256:16fa61e7481f4b77ef53991075de29fc5bacb582a1244046d2e8b4bb72ef66d0 \
--hash=sha256:194044c6b89a2f9f169df475cc167f6157eb9151cc69af8a2a163481d45cc407 \
--hash=sha256:1db3d807a14931fa317f96435695d9ec386be7b84b618cc61cfa5d08b0ae33d7 \
--hash=sha256:3261725c0ef84e7592597606f6583385fed2a5ec3909f43bc475ade9729a41d6 \
--hash=sha256:3b72c360427889b40f36dc214630e688c2fe03e16c162ef0aa41da7ab1455153 \
--hash=sha256:3e3a2599e640927089f932295a9a247fc40a5bdf69b0484532f530471a382750 \
--hash=sha256:3fc26e22840b77326a764ceb5f02ca2d342305fba08f002a8c1f139540cdfaad \
--hash=sha256:5067ee7f2bce36b11d0e334abcd1ccf8c541fc0bbdaf57cdd511fdee53e879b6 \
--hash=sha256:52e7bee800ec869b4031093875279f1ff2ed12c1e2f74923e8f49c916afd1d3b \
--hash=sha256:64760ba5331e3f1794d0bcaabc0d0c39e8c60bf67d09c93dc0e54189dfd7cfe5 \
--hash=sha256:765fa194a0f3372d83005ab83ab35d7c5526c4e22951e46059b8ac678b44fa5a \
--hash=sha256:79473cf8a5cbc471979bd9378c9f425384980fcf2ab6534b18ed7d0d9843987d \
--hash=sha256:896dd3a66959d3a5ddcfc140a53391f69ff1e8f25d93f0e2e7830c6de90ceb9d \
--hash=sha256:89ed49784ba88c221756ff4d4755dbc03b3c8d2c5103f6d6b4f83a0fb1e85294 \
--hash=sha256:ac7e48f7e7261207d750fa7e55eac2d45f720027d5703cd9007e9b37bbb59ac0 \
--hash=sha256:ad7353f6ddf285aeadfaf79e5a6829110106ff8189391704c1d8801aa0bae45a \
--hash=sha256:b0163a849b6f315bf52815e238bc2b2346604413fa7c1601eea84bcddb5fb9ac \
--hash=sha256:b6c9b706316d7b5a137c35e14f4103e2115b088c412140fdbd5f87c73284df61 \
--hash=sha256:c2e5856248a416767322c8668ef1845ad46ee62629266f84a8f007a317141013 \
--hash=sha256:ca9f6784ea96b55ff41708b92c3f6aeaebde4c560308e5fbbd3173fbc466e94e \
--hash=sha256:d1a5bd52d684e49a36582193e0b89ff267704cd4025abefb9e26803adeb3e5fb \
--hash=sha256:d3971e2749a723e9084dd507584e2a2761f78ad2c638aa31e80bc7a15c9db4f9 \
--hash=sha256:d4ef6cc305394ed669d4d9eebf10d3a101059bdcf2669c366ec1d14e4fb227bd \
--hash=sha256:d9e69ae01f99abe6ad646947bba8941e896cb3aa805be2597a0400e0764b5818
# via secretstorage
filenuke==0.0.0 \ filenuke==0.0.0 \
--hash=sha256:147011c0125121469cae0a8a7f4df399f470e54aa29a08f2d2c099bf0118dcee \ --hash=sha256:147011c0125121469cae0a8a7f4df399f470e54aa29a08f2d2c099bf0118dcee \
--hash=sha256:c55535dcecfdb27c5f4ce664d46e115950b5429763b5db75c198053646177f8f --hash=sha256:c55535dcecfdb27c5f4ce664d46e115950b5429763b5db75c198053646177f8f
@ -95,7 +124,9 @@ inflect==6.0.0 \
jaraco-classes==3.2.2 \ jaraco-classes==3.2.2 \
--hash=sha256:6745f113b0b588239ceb49532aa09c3ebb947433ce311ef2f8e3ad64ebb74594 \ --hash=sha256:6745f113b0b588239ceb49532aa09c3ebb947433ce311ef2f8e3ad64ebb74594 \
--hash=sha256:e6ef6fd3fcf4579a7a019d87d1e56a883f4e4c35cfe925f86731abc58804e647 --hash=sha256:e6ef6fd3fcf4579a7a019d87d1e56a883f4e4c35cfe925f86731abc58804e647
# via jaraco-collections # via
# jaraco-collections
# keyring
jaraco-collections==3.5.2 \ jaraco-collections==3.5.2 \
--hash=sha256:072b93eb35f9e48508485755534e66a34ef1cc84af291fd27f39b44d4c0dd2c3 \ --hash=sha256:072b93eb35f9e48508485755534e66a34ef1cc84af291fd27f39b44d4c0dd2c3 \
--hash=sha256:1ca12fa4b7067dfc8d7f791c1a8660d970a2bf2f80536ba0aa5cbb71fe1261f1 --hash=sha256:1ca12fa4b7067dfc8d7f791c1a8660d970a2bf2f80536ba0aa5cbb71fe1261f1
@ -115,6 +146,12 @@ jaraco-text==3.9.1 \
--hash=sha256:3ca615c4135e151d21206075ec4aface8a2fbc3e68437fe709a6541428a635f9 \ --hash=sha256:3ca615c4135e151d21206075ec4aface8a2fbc3e68437fe709a6541428a635f9 \
--hash=sha256:d57cd4448a588020318425e04194e897f96fc23b92b82ff9308a24d5cbf2b3fb --hash=sha256:d57cd4448a588020318425e04194e897f96fc23b92b82ff9308a24d5cbf2b3fb
# via jaraco-collections # via jaraco-collections
jeepney==0.8.0 \
--hash=sha256:5efe48d255973902f6badc3ce55e2aa6c5c3b3bc642059ef3a91247bcfcc5806 \
--hash=sha256:c0a454ad016ca575060802ee4d590dd912e35c122fa04e70306de3d076cce755
# via
# keyring
# secretstorage
json-rpc==1.13.0 \ json-rpc==1.13.0 \
--hash=sha256:84b45058e5ba95f49c7b6afcf7e03ab86bee89bf2c01f3ad8dd41fe114fc1f84 \ --hash=sha256:84b45058e5ba95f49c7b6afcf7e03ab86bee89bf2c01f3ad8dd41fe114fc1f84 \
--hash=sha256:def0dbcf5b7084fc31d677f2f5990d988d06497f2f47f13024274cfb2d5d7589 --hash=sha256:def0dbcf5b7084fc31d677f2f5990d988d06497f2f47f13024274cfb2d5d7589
@ -123,6 +160,10 @@ kasten==3.0.0 \
--hash=sha256:52894af46d6e1339f0d5fa8961892b292f99176848bce11877fe4a435b6782e5 \ --hash=sha256:52894af46d6e1339f0d5fa8961892b292f99176848bce11877fe4a435b6782e5 \
--hash=sha256:b22ebdc5f475c2ef9ab74abc36552add0b37732a7ce2be6bd7977ee41b2163b4 --hash=sha256:b22ebdc5f475c2ef9ab74abc36552add0b37732a7ce2be6bd7977ee41b2163b4
# via onionrblocks # via onionrblocks
keyring==23.9.3 \
--hash=sha256:69732a15cb1433bdfbc3b980a8a36a04878a6cfd7cb99f497b573f31618001c0 \
--hash=sha256:69b01dd83c42f590250fe7a1f503fc229b14de83857314b1933a3ddbf595c4a5
# via -r static-data/official-plugins/wot/requirements.in
mimcvdf==1.2.1 \ mimcvdf==1.2.1 \
--hash=sha256:7c837c46cfb9dce4ba895bc706a69646d4d5185c66aeaa333b5cfaa9a7d06dc4 --hash=sha256:7c837c46cfb9dce4ba895bc706a69646d4d5185c66aeaa333b5cfaa9a7d06dc4
# via kasten # via kasten
@ -300,6 +341,10 @@ pytz==2022.2.1 \
--hash=sha256:220f481bdafa09c3955dfbdddb7b57780e9a94f5127e35456a48589b9e0c0197 \ --hash=sha256:220f481bdafa09c3955dfbdddb7b57780e9a94f5127e35456a48589b9e0c0197 \
--hash=sha256:cea221417204f2d1a2aa03ddae3e867921971d0d76f14d87abb4414415bbdcf5 --hash=sha256:cea221417204f2d1a2aa03ddae3e867921971d0d76f14d87abb4414415bbdcf5
# via tempora # via tempora
secretstorage==3.3.3 \
--hash=sha256:2403533ef369eca6d2ba81718576c5e0f564d5cca1b58f73a8b23e7d4eeebd77 \
--hash=sha256:f356e6628222568e3af06f2eba8df495efa13b3b63081dafd4f7d9a7b7bc9f99
# via keyring
six==1.16.0 \ six==1.16.0 \
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \ --hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254 --hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254

View File

@ -35,7 +35,7 @@ def get_arguments() -> dict:
('version',): version.version, ('version',): version.version,
('start', 'daemon'): daemonlaunch.start, ('start', 'daemon'): daemonlaunch.start,
('stop', 'kill'): daemonlaunch.kill_daemon, ('stop', 'kill'): daemonlaunch.kill_daemon,
('resetplugins', 'reset-plugins'): resetplugins.reset ('resetplugins', 'reset-plugins', 'updateplugins', 'update-plugins'): resetplugins.reset
} }
return args return args

View File

@ -4,15 +4,18 @@ Web of Trust Plugin
""" """
import sys import sys
import os import os
import base64
import locale import locale
from time import sleep from time import sleep
import traceback
from typing import Set, TYPE_CHECKING from typing import Set, TYPE_CHECKING
from threading import Thread, local
import keyring.errors
from nacl.signing import SigningKey
from gossip.peerset import gossip_peer_set from gossip.peerset import gossip_peer_set
from logger import log as logging from logger import log as logging
import config import config
import onionrplugins
from onionrplugins.pluginapis import plugin_apis from onionrplugins.pluginapis import plugin_apis
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
@ -35,7 +38,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
plugin_name = 'wot' plugin_name = 'wot'
PLUGIN_VERSION = '0.0.1' PLUGIN_VERSION = '0.0.1'
from wot.identity import identities from wot.identity import Identity, identities
from wot import wotkeyring from wot import wotkeyring
from cli import main_ui from cli import main_ui
from onionrplugins import plugin_apis from onionrplugins import plugin_apis
@ -46,7 +49,13 @@ from wot.loadfromblocks import load_identities_from_blocks
def on_init(api, data=None): def on_init(api, data=None):
def load_identity_from_config(identity_name: str): def load_identity_from_config(identity_name: str):
identity_base85_key = config.get('wot.identity.{identity_name}') identity_base85_key = config.get('wot.identity.{identity_name}', '')
if not identity_base85_key:
raise KeyError('Identity not found in config')
key = SigningKey(base64.base85decode(identity_base85_key))
identity = identities.Identity(identity_name, key)
return identity
logging.info( logging.info(
f"Web of Trust Plugin v{PLUGIN_VERSION} enabled") f"Web of Trust Plugin v{PLUGIN_VERSION} enabled")
@ -61,22 +70,59 @@ def on_init(api, data=None):
# load active identity, from there load our trust graph # load active identity, from there load our trust graph
active_identity = config.get('wot.active_identity_name', '') active_identity = config.get('wot.active_identity_name', '')
if active_identity: if not active_identity:
try: try:
script = sys.argv[0] + ' ' script = sys.argv[0] + ' '
except IndexError: except IndexError:
script = '' script = ''
logging.info( logging.info(
"Generate a web of trust identity with '{script}wot new" + f"Generate a web of trust identity with '{script}wot new" +
"<name>' and restart Onionr") "<name>' and restart Onionr")
return return
if config.get('wot.use_system_keyring', True):
iden = wotkeyring.get_identity_by_name(active_identity) try:
else:
# load from file
iden = load_identity_from_config(active_identity) iden = load_identity_from_config(active_identity)
except KeyError:
try:
iden = wotkeyring.get_identity_by_name(active_identity)
except KeyError:
logging.error(
"Active identity's private key not found in config or keyring")
return
logging.info('Loaded active identity: ' + iden.name)
def on_wot_cmd(api, data=None): def on_wot_cmd(api, data=None):
main_ui() def _create_new_iden():
iden = Identity(
SigningKey.generate(),
input('Enter a name for your identity: '))
try:
wotkeyring.set_identity(iden)
except keyring.errors.NoKeyringError:
logging.warn(
"Could not use secure keyring to store your WOT " +
"private key, using config.")
logging.info("Using config file to store identity private key")
config.set(
'wot.identity.{iden.name}',
base64.b85encode(
bytes(iden.private_key)).decode('utf-8'), savefile=True)
config.set(
'wot.active_identity_name', iden.name, savefile=True)
logging.info(
'Identity created and automatically set as active. ' +
'Restart Onionr to use it.')
try:
cmd = sys.argv[2]
except IndexError:
cmd = ''
match cmd:
case 'new':
try:
_create_new_iden()
except KeyboardInterrupt:
pass
case '':
main_ui()

View File

@ -1,18 +1,22 @@
import base64
import keyring import keyring
from identity import Identity from wot.identity import Identity
def get_identity_by_name(name: str) -> 'Identity': def get_identity_by_name(name: str) -> 'Identity':
iden_key = keyring.get_credential('onionr.wot', name) iden_key = keyring.get_credential('onionr.wot', name)
iden_key = base64.b85decode(iden_key)
if not iden_key: if not iden_key:
raise KeyError('Identity not found') raise KeyError('Identity not found')
return Identity(iden_key, name) return Identity(iden_key, name)
def set_identity_by_name(identity: 'Identity', name: str) -> None: def set_identity(identity: 'Identity') -> None:
name = identity.name
if identity.private_key: if identity.private_key:
keyring.set_credential('onionr.wot', name, identity.private_key) keyring.set_password('onionr.wot', name, base64.b85encode(bytes(identity.private_key)))
else: else:
raise ValueError('Cannot set identity with no private key') raise ValueError('Cannot set identity with no private key')