"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/lib/datahandler/rvl.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.

rvl.py  (revelation-0.5.3.tar.xz):rvl.py  (revelation-0.5.4.tar.xz)
skipping to change at line 36 skipping to change at line 36
from . import base from . import base
from revelation import config, data, entry, util from revelation import config, data, entry, util
from revelation.bundle import luks from revelation.bundle import luks
from Cryptodome.Protocol.KDF import PBKDF2 from Cryptodome.Protocol.KDF import PBKDF2
from Cryptodome.Hash import SHA1 from Cryptodome.Hash import SHA1
from Cryptodome.Random import get_random_bytes from Cryptodome.Random import get_random_bytes
import os, re, struct, xml.dom.minidom, zlib import os, re, struct, xml.dom.minidom, zlib
from io import StringIO from io import BytesIO
from xml.parsers.expat import ExpatError from xml.parsers.expat import ExpatError
from Cryptodome.Cipher import AES from Cryptodome.Cipher import AES
import hashlib import hashlib
class RevelationXML(base.DataHandler): class RevelationXML(base.DataHandler):
"Handler for Revelation XML data" "Handler for Revelation XML data"
name = "XML" name = "XML"
skipping to change at line 138 skipping to change at line 138
except ValueError: except ValueError:
raise base.DataError raise base.DataError
def check(self, input): def check(self, input):
"Checks if the data is valid" "Checks if the data is valid"
if input is None: if input is None:
raise base.FormatError raise base.FormatError
match = re.match(""" if isinstance(input, str):
input = input.encode()
match = re.match(b"""
\s* # whitespace at beginning \s* # whitespace at beginning
<\?xml(?:.*)\?> # xml header <\?xml(?:.*)\?> # xml header
\s* # whitespace after xml header \s* # whitespace after xml header
<revelationdata # open revelationdata tag <revelationdata # open revelationdata tag
[^>]+ # any non-closing character [^>]+ # any non-closing character
dataversion="(\d+)" # dataversion dataversion="(\d+)" # dataversion
[^>]* # any non-closing character [^>]* # any non-closing character
> # close revelationdata tag > # close revelationdata tag
""", input, re.VERBOSE) """, input, re.VERBOSE)
skipping to change at line 535 skipping to change at line 538
self.luks_header = None self.luks_header = None
self.luks_buff = None self.luks_buff = None
self.current_slot = False self.current_slot = False
def check(self, input): def check(self, input):
"Checks if the data is valid" "Checks if the data is valid"
if input is None: if input is None:
raise base.FormatError raise base.FormatError
sbuf = StringIO(input) sbuf = BytesIO(input)
l = luks.LuksFile() l = luks.LuksFile()
try: try:
l.load_from_file(sbuf) l.load_from_file(sbuf)
except: except:
l.close() l.close()
raise base.FormatError raise base.FormatError
skipping to change at line 578 skipping to change at line 581
# data needs to be padded to 512 bytes # data needs to be padded to 512 bytes
# We use Merkle-Damgard length padding (1 bit followed by 0 bits + size) # We use Merkle-Damgard length padding (1 bit followed by 0 bits + size)
# http://en.wikipedia.org/wiki/Merkle-Damg%C3%A5rd_hash_function # http://en.wikipedia.org/wiki/Merkle-Damg%C3%A5rd_hash_function
padlen = 512 - (len(data) % 512) padlen = 512 - (len(data) % 512)
if padlen < 4: if padlen < 4:
padlen = 512 + padlen padlen = 512 + padlen
if padlen > 4: if padlen > 4:
data += "\x80" + "\x00" * (padlen - 5) data += bytes([128] + [0] * (padlen - 5))
data += struct.pack("<I", padlen) data += struct.pack("<I", padlen)
# create a new luks file in memory # create a new luks file in memory
buffer = StringIO() buffer = BytesIO()
luksfile = luks.LuksFile() luksfile = luks.LuksFile()
luksfile.create(buffer, "aes", "cbc-essiv:sha256", "sha1", 16, 400) luksfile.create(buffer, "aes", "cbc-essiv:sha256", "sha1", 16, 400)
luksfile.set_key(0, password, 5000, 400) luksfile.set_key(0, password, 5000, 400)
# encrypt the data # encrypt the data
luksfile.encrypt_data(0, data) luksfile.encrypt_data(0, data)
buffer.seek(0) buffer.seek(0)
return buffer.read() return buffer.read()
def import_data(self, input, password): def import_data(self, input, password):
"Imports data into an entrystore" "Imports data into an entrystore"
# check password # check password
if password is None: if password is None:
raise base.PasswordError raise base.PasswordError
# create a LuksFile # create a LuksFile
buffer = StringIO(input) buffer = BytesIO(input)
luksfile = luks.LuksFile() luksfile = luks.LuksFile()
try: try:
luksfile.load_from_file(buffer) luksfile.load_from_file(buffer)
except: except:
luksfile.close() luksfile.close()
buffer.close() buffer.close()
raise base.FormatError raise base.FormatError
slot = luksfile.open_any_key(password) slot = luksfile.open_any_key(password)
if slot == None: if slot is None:
luksfile.close() luksfile.close()
buffer.close() buffer.close()
raise base.PasswordError raise base.PasswordError
data = luksfile.decrypt_data(0, luksfile.data_length()) data = luksfile.decrypt_data(0, luksfile.data_length())
# remove the pad, and decompress # remove the pad, and decompress
padlen = struct.unpack("<I", data[-4:])[0] padlen = struct.unpack("<I", data[-4:])[0]
data = zlib.decompress(data[0:-padlen]).decode() data = zlib.decompress(data[0:-padlen]).decode()
 End of changes. 7 change blocks. 
7 lines changed or deleted 10 lines changed or added

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