"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/lib/datahandler/gpass.py" between
revelation-0.5.3.tar.xz and revelation-0.5.4.tar.xz

About: Revelation is a password manager for the GNOME 3 desktop.

gpass.py  (revelation-0.5.3.tar.xz):gpass.py  (revelation-0.5.4.tar.xz)
skipping to change at line 33 skipping to change at line 33
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
from . import base from . import base
from revelation import data, entry from revelation import data, entry
import locale, re import locale, re
from Cryptodome.Cipher import Blowfish from Cryptodome.Cipher import Blowfish
from Cryptodome.Hash import SHA from Cryptodome.Hash import SHA
IV = "\x05\x17\x01\x7b\x0c\x03\x36\x5e" IV = b"\x05\x17\x01\x7b\x0c\x03\x36\x5e"
def decrypt(ciphertext, password, magic = None): def decrypt(ciphertext, password, magic = None):
"Decrypts a data stream" "Decrypts a data stream"
# decrypt data # decrypt data
if len(ciphertext) % 8 != 0: if len(ciphertext) % 8 != 0:
raise base.FormatError raise base.FormatError
key = SHA.new(password).digest() key = SHA.new(password.encode()).digest()
cipher = Blowfish.new(key, Blowfish.MODE_CBC, IV) cipher = Blowfish.new(key, Blowfish.MODE_CBC, IV)
plaintext = cipher.decrypt(ciphertext) plaintext = cipher.decrypt(ciphertext)
# check magic string # check magic string
if magic != None: if magic != None:
if plaintext[:len(magic)] != magic: if plaintext[:len(magic)].decode() != magic:
raise base.PasswordError raise base.PasswordError
else: else:
plaintext = plaintext[len(magic):] plaintext = plaintext[len(magic):]
# remove padding # remove padding
padchar = plaintext[-1] padchar = plaintext[-1]
npadchar = ord(padchar) npadchar = padchar
if (npadchar > 0): if (npadchar > 0):
if plaintext[-npadchar:] != padchar * npadchar: if plaintext[-npadchar:] != bytes([padchar] * npadchar):
raise base.FormatError raise base.FormatError
plaintext = plaintext[:-npadchar] plaintext = plaintext[:-npadchar]
return plaintext return plaintext.decode()
def encrypt(plaintext, password): def encrypt(plaintext, password):
"Encrypts a data stream" "Encrypts a data stream"
# right-pad data # right-pad data
padlen = 8 - len(plaintext) % 8 padlen = 8 - len(plaintext) % 8
if padlen == 0: if padlen == 0:
padlen = 8 padlen = 8
plaintext += chr(padlen) * padlen plaintext += bytes([padlen] * padlen)
# encrypt data # encrypt data
key = SHA.new(password).digest() key = SHA.new(password).digest()
cipher = Blowfish.new(key, Blowfish.MODE_CBC, IV) cipher = Blowfish.new(key, Blowfish.MODE_CBC, IV)
return cipher.encrypt(plaintext) return cipher.encrypt(plaintext)
class GPass04(base.DataHandler): class GPass04(base.DataHandler):
"Data handler for GPass 0.4.x data" "Data handler for GPass 0.4.x data"
skipping to change at line 109 skipping to change at line 109
iter = entrystore.iter_nth_child(None, 0) iter = entrystore.iter_nth_child(None, 0)
while iter is not None: while iter is not None:
e = entrystore.get_entry(iter) e = entrystore.get_entry(iter)
if type(e) != entry.FolderEntry: if type(e) != entry.FolderEntry:
e = e.convert_generic() e = e.convert_generic()
data += e.name + "\n" data += e.name + "\n"
data += e[entry.UsernameField] + "\n" data += (e[entry.UsernameField] or "") + "\n"
data += e[entry.PasswordField] + "\n" data += (e[entry.PasswordField] or "") + "\n"
data += e[entry.HostnameField] + "\n" data += (e[entry.HostnameField] or "") + "\n"
data += str(e.updated) + "\n" data += str(e.updated) + "\n"
data += str(e.updated) + "\n" data += str(e.updated) + "\n"
data += "0\n" data += "0\n"
data += str(len(e.description) + 1) + "\n" data += str(len(e.description) + 1) + "\n"
data += e.description + "\n" data += e.description + "\n"
iter = entrystore.iter_traverse_next(iter) iter = entrystore.iter_traverse_next(iter)
return encrypt(data, password) return encrypt(data.encode(), password.encode())
def import_data(self, input, password): def import_data(self, input, password):
"Imports data from a data stream to an entrystore" "Imports data from a data stream to an entrystore"
plaintext = decrypt(input, password, "GNOME Password Manager\n") plaintext = decrypt(input, password, "GNOME Password Manager\n")
entrystore = data.EntryStore() entrystore = data.EntryStore()
lines = plaintext.splitlines() lines = plaintext.splitlines()
while len(lines) > 0: while len(lines) > 0:
skipping to change at line 210 skipping to change at line 210
def __mkstr(self, input): def __mkstr(self, input):
"Makes a string suitable for inclusion in the data stream" "Makes a string suitable for inclusion in the data stream"
return self.__mkint(len(input)) + input return self.__mkint(len(input)) + input
def __normstr(self, string): def __normstr(self, string):
"Normalizes a string" "Normalizes a string"
string = re.sub("[\r\n]+", " ", string) string = re.sub("[\r\n]+", " ", string)
string = string.decode(locale.getpreferredencoding(), "replace")
string = string.encode("utf-8", "replace")
return string return string
def __packint(self, input): def __packint(self, input):
"Packs an integer" "Packs an integer"
if input == 0: if input == 0:
return "\x00" return "\x00"
string = "" string = ""
while input > 0: while input > 0:
c = input % 0x80 c = input % 0x80
input = input / 0x80 input = input // 0x80
if input > 0: if input > 0:
c |= 0x80 c |= 0x80
string += chr(c) string += chr(c)
return string return string
def __packstr(self, input): def __packstr(self, input):
"Packs a string" "Packs a string"
skipping to change at line 282 skipping to change at line 280
"Exports data from an entrystore" "Exports data from an entrystore"
plaintext = "GPassFile version 1.1.0" plaintext = "GPassFile version 1.1.0"
iter = entrystore.iter_children(None) iter = entrystore.iter_children(None)
id = 0 id = 0
foldermap = {} foldermap = {}
while iter != None: while iter != None:
id += 1 id += 1
path = entrystore.get_path(iter) path = entrystore.get_path(iter).to_string()
parentpath = path[:-1] parentpath = ':'.join(path.split(':')[:-1])
if len(parentpath) > 0 and parentpath in foldermap: if len(parentpath) > 0 and parentpath in foldermap:
parentid = foldermap[parentpath] parentid = foldermap[parentpath]
else: else:
parentid = 0 parentid = 0
e = entrystore.get_entry(iter) e = entrystore.get_entry(iter)
if type(e) == entry.FolderEntry: if type(e) == entry.FolderEntry:
skipping to change at line 313 skipping to change at line 311
attrdata = "" attrdata = ""
attrdata += self.__packstr(e.name) attrdata += self.__packstr(e.name)
attrdata += self.__packstr(e.description) attrdata += self.__packstr(e.description)
attrdata += self.__packint(e.updated) attrdata += self.__packint(e.updated)
attrdata += self.__packint(e.updated) attrdata += self.__packint(e.updated)
attrdata += self.__packint(0) attrdata += self.__packint(0)
attrdata += self.__packint(0) attrdata += self.__packint(0)
if type(e) == entry.GenericEntry: if type(e) == entry.GenericEntry:
attrdata += self.__packstr(e[entry.UsernameField]) attrdata += self.__packstr(e[entry.UsernameField] or "")
attrdata += self.__packstr(e[entry.PasswordField]) attrdata += self.__packstr(e[entry.PasswordField] or "")
attrdata += self.__packstr(e[entry.HostnameField]) attrdata += self.__packstr(e[entry.HostnameField] or "")
entrydata += self.__mkstr(attrdata) entrydata += self.__mkstr(attrdata)
plaintext += entrydata plaintext += entrydata
iter = entrystore.iter_traverse_next(iter) iter = entrystore.iter_traverse_next(iter)
return encrypt(plaintext, password) return encrypt(plaintext.encode(), password.encode())
def import_data(self, input, password): def import_data(self, input, password):
"Imports data from a data stream to an entrystore" "Imports data from a data stream to an entrystore"
plaintext = decrypt(input, password, "GPassFile version 1.1.0") plaintext = decrypt(input, password, "GPassFile version 1.1.0")
entrystore = data.EntryStore() entrystore = data.EntryStore()
foldermap = {} foldermap = {}
while len(plaintext) > 0: while len(plaintext) > 0:
 End of changes. 14 change blocks. 
20 lines changed or deleted 18 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)