Compare commits

..

No commits in common. "a871c2a6812691e9c12111c174f7a590f197e8e0" and "0148a3672659c0d8300611d236ae316db76fc931" have entirely different histories.

3 changed files with 25 additions and 102 deletions

View File

@ -30,14 +30,13 @@ to stdout
to a file.
```
usage: tox_savefile.py [-h]
usage: tox_savefile.py [-h] [--output OUTPUT]
[--command info|decrypt|nodes|edit]
[--info info|repr|yaml|json|pprint|nmap_udp|nmap_tcp]
[--indent INDENT]
[--nodes select_tcp|select_udp|select_version|nmap_tcp|nmap_udp,download]
[--download_nodes_url DOWNLOAD_NODES_URL]
[--edit help|section,num,key,val]
[--output OUTPUT]
profile
```
Positional arguments:
@ -49,7 +48,7 @@ Optional arguments:
-h, --help show this help message and exit
--command {info,decrypt,nodes,edit}
Action command - default: info
--output OUTPUT Destination for info/decrypt/nodes - can be the same as input
--output OUTPUT Destination for info/decrypt/nodes - defaults to stdout
--info info|repr|yaml|json|pprint|nmap_udp|nmap_tcp (may require nmap)
Format for info command
--indent INDENT Indent for yaml/json/pprint
@ -112,36 +111,17 @@ Currently it is:
NAME,.,Nick_name,str
STATUSMESSAGE,.,Status_message,str
STATUS,.,Online_status,int
NOSPAMKEYS,.,Nospam,hexstr
NOSPAMKEYS,.,Public_key,hexstr
NOSPAMKEYS,.,Private_key,hexstr
```
The ```num``` field is to accomodate sections that have lists:
* ```.``` is a placeholder for sections that don't have lists.
* ```<int>``` is for the nth element of the list, zero-based.
* ```*``` is for all elements of the list.
The ```--output``` can be the same as input as the input file is read
and closed before processing starts.
You can use the ```---edit``` command to synchronize profiles, by
keeping the keypair and synchronize profiles between different clients:
e.g. your could keep your profile from toxic as master, and copy it over
your qtox/toxygen/TriFa profile while preserving their keypair and NOSPAM:
1. Use ```--command info --info info``` on the target profile to get the
```Nospam```, ```Public_key``` and ```Private_key``` of the target.
2. Backup the target and copy the source profile to the target.
3. Edit the target with the values from 1) with:```
--command edit --edit NOSPAMKEYS,.,Nospam,hexstr --output target target
--command edit --edit NOSPAMKEYS,.,Public_key,hexstr --output target target
--command edit --edit NOSPAMKEYS,.,Private_key,hexstr --output target target
```
## Requirements
If you want to read encrypted profiles, you need to download
toxygen_wrapper to deal with encrypted tox files, from:
toxygen to deal with encrypted tox files, from:
<https://git.plastiras.org/emdee/toxygen_wrapper>
Just put the toxygen/toxygen directory on your PYTHONPATH
You also need to link your libtoxcore.so and libtoxav.so
@ -168,9 +148,14 @@ required. It's available in most distros, or <https://nmap.org/>
This has not been tested on Windwoes, but is should be simple to fix.
Because it's written in Python it is easy to extend to, for example,
supporting multidevices:
rekeying a profile when copying a profile to a new device:
<https://git.plastiras.org/emdee/tox_profile/wiki/MultiDevice-Announcements-POC>
Or you could keep the keypair and synchronize profiles between different
clients: e.g. your could keep your profile from toxic as master,
and copy it over your qtox/toxygen/TriFa profile while preserving their
ToxId keypair.
## Specification
There is a copy of the Tox [spec](https://toktok.ltd/spec.html)

View File

@ -113,19 +113,12 @@ LOG.trace = trace
global bOUT, aOUT, sENC
aOUT = {}
bOUT = b''
sENC = sys.getdefaultencoding() # 'utf-8'
lNULLS = ['', '[]', 'null']
sENC = 'utf-8'
# grep '#''#' logging_tox_savefile.py|sed -e 's/.* //'
sEDIT_HELP = """
NAME,.,Nick_name,str
STATUSMESSAGE,.,Status_message,str
STATUS,.,Online_status,int
NOSPAMKEYS,.,Nospam,hexstr
NOSPAMKEYS,.,Public_key,hexstr
NOSPAMKEYS,.,Private_key,hexstr
DHT,.,DHTnode,
TCP_RELAY,.,TCPnode,
PATH_NODE,.,PATHnode,
"""
#messenger.c
@ -445,7 +438,7 @@ def process_chunk(index, state, oArgs=None):
label = dSTATE_TYPE[data_type]
if oArgs.command == 'edit' and oArgs.edit:
section,num,key,val = oArgs.edit.split(',', 3)
section,num,key,val = oArgs.edit.split(',',3)
diff = index - len(bOUT)
if bDEBUG and diff > 0:
@ -464,48 +457,15 @@ def process_chunk(index, state, oArgs=None):
"Public_key": f"{public_key}",
"Private_key": f"{private_key}"}
aOUT.update({label: aIN})
if oArgs.command == 'edit' and section == label:
## NOSPAMKEYS,.,Nospam,hexstr
if key == "Nospam":
assert len(val) == 4*2, val
result = bytes.fromhex (val) +result[4:]
LOG.info(f"{label} {key} EDITED to {val}")
## NOSPAMKEYS,.,Public_key,hexstr
elif key == "Public_key":
assert len(val) == 32 * 2, val
result = +result[0:4] +bytes.fromhex(val) +result[36:]
LOG.info(f"{label} {key} EDITED to {val}")
## NOSPAMKEYS,.,Private_key,hexstr
elif key == "Private_key":
assert len(val) == 32 * 2, val
result = +result[0:36] +bytes.fromhex(val)
LOG.info(f"{label} {key} EDITED to {val}")
elif data_type == MESSENGER_STATE_TYPE_DHT:
LOG.debug(f"process_chunk {label} length={length}")
if length > 4:
lIN = lProcessDHTnodes(state, index, length, result, "DHTnode")
else:
lIN = []
LOG.info(f"NO {label}")
lIN = lProcessDHTnodes(state, index, length, result)
aOUT.update({label: lIN})
if oArgs.command == 'edit' and section == label:
## DHT,.,DHTnode,
if num == '.' and key == "DHTnode" and val in lNULLS:
# 4 uint32_t (0x159000D)
status = 0x159000D
# FixMe - dunno
result = struct.pack("<L", status)
length = 4
LOG.info(f"{label} {key} EDITED to {val}")
elif data_type == MESSENGER_STATE_TYPE_FRIENDS:
LOG.info(f"{label} {length // 2216} FRIENDS {length % 2216}")
if length > 0:
lIN = lProcessFriends(state, index, length, result)
else:
lIN = []
LOG.info(f"NO {label}")
aOUT.update({label: lIN})
elif data_type == MESSENGER_STATE_TYPE_NAME:
@ -562,12 +522,6 @@ def process_chunk(index, state, oArgs=None):
lIN = []
LOG.info(f"NO {label}")
aOUT.update({label: lIN})
if oArgs.command == 'edit' and section == label:
## TCP_RELAY,.,TCPnode,
if num == '.' and key == "TCPnode" and val in lNULLS:
result = b''
length = 0
LOG.info(f"{label} {key} EDITED to {val}")
elif data_type == MESSENGER_STATE_TYPE_PATH_NODE:
#define NUM_SAVED_PATH_NODES 8
@ -578,12 +532,6 @@ def process_chunk(index, state, oArgs=None):
LOG.debug(f"process_chunk {label} bytes={length}")
lIN = lProcessNodeInfo(state, index, length, result, "PATHnode")
aOUT.update({label: lIN})
if oArgs.command == 'edit' and section == label:
## PATH_NODE,.,PATHnode,
if num == '.' and key == "PATHnode" and val in lNULLS:
result = b''
length = 0
LOG.info(f"{label} {key} EDITED to {val}")
elif data_type == MESSENGER_STATE_TYPE_CONFERENCES:
lIN = []
@ -738,9 +686,8 @@ def oMainArgparser(_=None):
choices=['info', 'decrypt', 'nodes', 'edit'],
required=True,
help='Action command - default: info')
# nargs='+',
parser.add_argument('--edit', type=str, default='',
help='comma seperated SECTION,num,key,value - or help for ')
help='comma seperated SECTION,key,value - unfinished')
parser.add_argument('--indent', type=int, default=2,
help='Indent for yaml/json/pprint')
choices=['info', 'save', 'repr', 'yaml','json', 'pprint']

View File

@ -104,26 +104,17 @@ for the_tox in $tox /tmp/toxic_profile.save ; do
$EXE $target --command edit --edit help $the_tox 2>/dev/null || exit ${i}2
# edit the status message
INFO $i $the_base.Status_message 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic'
INFO $i $the_base.edit1 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic'
$EXE $target --command edit --edit 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic' \
--output $the_base.Status_message.tox $the_tox 2>&1|grep EDIT || exit ${i}3
[ -s $the_base.Status_message.tox ] || exit ${i}3
$EXE $target --command info $the_base.Status_message.tox 2>&1|grep Toxxed || exit ${i}4
--output $the_base.edit1.tox $the_tox 2>&1|grep EDIT
[ -s $the_base.edit1.tox ] || exit ${i}3
$EXE $target --command info $the_base.edit1.tox 2>&1|grep Toxxed || exit ${i}4
# edit the nick_name
INFO $i $the_base.Nick_name 'NAME,.,Nick_name,FooBar'
INFO $i $the_base.edit2 'NAME,.,Nick_name,FooBar'
$EXE $target --command edit --edit 'NAME,.,Nick_name,FooBar' \
--output $the_base.Nick_name.tox $the_tox 2>&1|grep EDIT || exit ${i}5
[ -s $the_base.Nick_name.tox ] || exit ${i}5
$EXE $target --command info $the_base.Nick_name.tox 2>&1|grep FooBar || exit ${i}6
# set the DHTnodes to empty
INFO $i $the_base.noDHT 'DHT,.,DHTnode,'
$EXE $target --command edit --edit 'DHT,.,DHTnode,' \
--output $the_base.noDHT.tox $the_tox 2>&1|grep EDIT || exit ${i}7
[ -s $the_base.noDHT.tox ] || exit ${i}7
$EXE $target --command info $the_base.noDHT.tox 2>&1|grep 'NO DHT' || exit ${i}8
--output $the_base.edit2.tox $the_tox 2>&1|grep EDIT
[ -s $the_base.edit2.tox ] || exit ${i}5
$EXE $target --command info $the_base.edit2.tox 2>&1|grep FooBar || exit ${i}6
done