Recover keys?


Recommended Posts

It's really easy to click the little '-' button accidentally in the BitTorrent Sync interface which immediately deletes the shared folder. How can I recover the keys that I used for that folder? I have distributed the read-only key but not the read-write key, so I don't have a copy of it.

Feature request: confirmation dialog before deleting a folder from Sync.

Link to comment
Share on other sites

If you're quick, you can recover lost keys from the backup "sync.dat.old" file (found in %AppData%\BitTorrent Sync on Windows)

If you open this file in a standard text editor, whilst it will look very messy, search for the phrase "secret32:" - each folder you were sharing will have it's key within this following context:

....<folder path will be here>6:secret32:<folder secret will be here>15:...

...this will only work if you're quick though and do this immediately after you inadvertently remove a folder from Sync, as the "sync.dat.old" file is an automated backup of the main "sync.dat" file, and is therefore updated at regular intervals!

I agree with you though, there should really be a confirmation dialog before you remove a folder from Sync!

Link to comment
Share on other sites

  • 3 weeks later...

I had an issue while testing out a newer version of btsync and had forgotten to backup the config files beforehand, then when I went back to the version my other devices were using it would not start up. I saw that I could recover the secrets and paths from sync.dat.old so I copied it and wrote a quick little python script to help me.

If anyone uses a unix type os I hope this script will save you some time, it is made to search /home/username/.sync and your current directory first.


#!/usr/bin/python
"""
This is a quick little script I made to parse out the key and path pairs from BTSync's config.
"""

# Imports
from sys import exit
from os import getenv
from os.path import exists,abspath

# G Vars
pwd = abspath('.')+"/" # sets the current directroy
defaultDirs = ((getenv("HOME")+"/.sync/sync.dat", getenv("HOME")+"/.sync/sync.dat.old"),
(pwd + "sync.dat", pwd + "sync.dat.old"))
#\
sync = "" # Dont touch!
syncOld = "" # Dont touch!
bigData = [] # Dont touch!

# Fns
def __sortData():
global bigData
f0 = open(sync, "r")
data = f0.read().split(":")
f0.close()
del f0
f1 = open(syncOld, "r")
tmp = f1.read().split(":")
f1.close()
del f1
tmpLen = len(tmp)
for i in range(0, tmpLen): data.append(tmp[i])
del tmp, tmpLen
dataLen = len(data)
for i in range(0, dataLen):
curLine = data[i]
# if curLine.find("path") != -1 and data[i+3][-2:] == '15': bigData.append({'path':data[i+1][:-1],'secret':data[i+3][:-2]})
if curLine.find("path") != -1 and data[i+3][-1:] == '7': bigData.append({'path':data[i+1][:-1],'secret':data[i+3][:-1]})
elif curLine.find("path") != -1 and data[i+3][-2:] == '15': bigData.append({'path':data[i+1][:-1],'secret':data[i+3][:-2]})
del data, dataLen, curLine
return 0
# end of sortData

def __setPaths():
global sync, syncOld
for i in range(0, len(defaultDirs)):
if exists(defaultDirs[i][0]) and exists(defaultDirs[i][1]):
sync = defaultDirs[i][0]
syncOld = defaultDirs[i][1]
break
if sync == '' or syncOld == "": return None
else: return 0
# end of setPath fn

def __printData():
print "------"
input = bigData
inputLen = len(input)
if inputLen == 0: return None
for i in range(0, inputLen):
print "Secret: " + input[i]['secret']
print " Path: " + input[i]['path']
if i != (inputLen-1): print "---"
print "------"
del input, inputLen
# end of printData dn

# Main
def main():
# Look for sync.dat and sync.day.old file
if __setPaths() == None:
print "There was an error finding the sync.dat files!"
exit(1)
# Read both files and put them together
if __sortData() == None:
print "There was an error sorting the data!"
exit(1)
# print data to screen
__printData()
# end of main fn
if __name__ == "__main__":
main()

Edit 1: -=:Updated 07/04/13 - to work with 1.1.27:=-

Edit 2: -=:Updated 07/22/13 - to work with 1.1.42:=-

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.