Ejemplo n.º 1
0
    def __xml_import_node(self, entrystore, node, parent=None):
        "Imports a node into an entrystore"

        try:

            # check the node
            if node.nodeType == node.TEXT_NODE:
                return

            if node.nodeType != node.ELEMENT_NODE or node.nodeName != "entry":
                raise base.FormatError

            # create an entry, iter needed for children
            e = self.__lookup_entry(node.attributes["type"].value)()
            iter = entrystore.add_entry(e, parent)

            # handle child nodes
            for child in node.childNodes:

                if child.nodeType != child.ELEMENT_NODE:
                    continue

                elif child.nodeName == "name":
                    e.name = util.dom_text(child)

                elif child.nodeName == "notes":
                    e.notes = util.dom_text(child)

                elif child.nodeName == "description":
                    e.description = util.dom_text(child)

                elif child.nodeName == "updated":
                    e.updated = int(util.dom_text(child))

                elif child.nodeName == "field":
                    e[self.__lookup_field(
                        child.attributes["id"].nodeValue)] = util.dom_text(
                            child)

                elif child.nodeName == "entry":
                    if type(e) != entry.FolderEntry:
                        raise base.DataError

                    self.__xml_import_node(entrystore, child, iter)

                else:
                    raise base.FormatError

            # update entry with actual data
            entrystore.update_entry(iter, e)

        except (entry.EntryTypeError, entry.EntryFieldError):
            raise base.DataError

        except KeyError:
            raise base.FormatError

        except ValueError:
            raise base.DataError
Ejemplo n.º 2
0
	def __xml_import_node(self, entrystore, node, parent = None):
		"Imports a node into an entrystore"

		try:

			# check the node
			if node.nodeType == node.TEXT_NODE:
				return

			if node.nodeType != node.ELEMENT_NODE or node.nodeName != "entry":
				raise base.FormatError

			# create an entry, iter needed for children
			e = self.__lookup_entry(node.attributes["type"].value)()
			iter = entrystore.add_entry(e, parent)

			# handle child nodes
			for child in node.childNodes:

				if child.nodeType != child.ELEMENT_NODE:
					continue

				elif child.nodeName == "name":
					e.name = util.dom_text(child)

				elif child.nodeName == "notes":
					e.notes = util.dom_text(child)

				elif child.nodeName == "description":
					e.description = util.dom_text(child)

				elif child.nodeName == "updated":
					e.updated = int(util.dom_text(child))

				elif child.nodeName == "field":
					e[self.__lookup_field(child.attributes["id"].nodeValue)] = util.dom_text(child)

				elif child.nodeName == "entry":
					if type(e) != entry.FolderEntry:
						raise base.DataError

					self.__xml_import_node(entrystore, child, iter)

				else:
					raise base.FormatError

			# update entry with actual data
			entrystore.update_entry(iter, e)


		except ( entry.EntryTypeError, entry.EntryFieldError ):
			raise base.DataError

		except KeyError:
			raise base.FormatError

		except ValueError:
			raise base.DataError
Ejemplo n.º 3
0
	def import_data(self, input, password):
		"Imports data into an entrystore"

		try:

			# check and load data
			self.check(input)
			dom = xml.dom.minidom.parseString(input.strip())

			if dom.documentElement.nodeName != "FPM":
				raise base.FormatError


			# set up decryption engine, and check if password is correct
			keynode = dom.documentElement.getElementsByTagName("KeyInfo")[0]
			salt = keynode.attributes["salt"].nodeValue
			vstring = keynode.attributes["vstring"].nodeValue

			password = MD5.new(salt + password).digest()
			cipher = Blowfish.new(password)

			if self.__decrypt(cipher, vstring) != "FIGARO":
				raise base.PasswordError

		except ExpatError:
			raise base.FormatError


		except ( IndexError, KeyError ):
			raise base.FormatError


		# import entries into entrystore
		entrystore = data.EntryStore()
		folders = {}

		for node in dom.getElementsByTagName("PasswordItem"):

			parent = None
			e = entry.GenericEntry()

			for fieldnode in [ node for node in node.childNodes if node.nodeType == node.ELEMENT_NODE ]:

				content = self.__decrypt(cipher, util.dom_text(fieldnode))

				if content == "":
					continue

				elif fieldnode.nodeName == "title":
					e.name = content

				elif fieldnode.nodeName == "user":
					e.get_field(entry.UsernameField).value = content

				elif fieldnode.nodeName == "url":
					e.get_field(entry.HostnameField).value = content

				elif fieldnode.nodeName == "password":
					e.get_field(entry.PasswordField).value = content
	
				elif fieldnode.nodeName == "notes":
					e.description = content

				elif fieldnode.nodeName == "category":

					if folders.has_key(content):
						parent = folders[content]

					else:
						folderentry = entry.FolderEntry()
						folderentry.name = content

						parent = entrystore.add_entry(folderentry)
						folders[content] = parent

			entrystore.add_entry(e, parent)

		return entrystore
Ejemplo n.º 4
0
	def import_data(self, input, password):
		"Imports data into an entrystore"

		try:

			# check and load data
			self.check(input)
			dom = xml.dom.minidom.parseString(input.strip())

			if dom.documentElement.nodeName != "FPM":
				raise base.FormatError


			# set up decryption engine, and check if password is correct
			keynode = dom.documentElement.getElementsByTagName("KeyInfo")[0]
			salt = keynode.attributes["salt"].nodeValue
			vstring = keynode.attributes["vstring"].nodeValue

			password = MD5.new(salt + password).digest()
			cipher = Blowfish.new(password)

			if self.__decrypt(cipher, vstring) != "FIGARO":
				raise base.PasswordError

		except ExpatError:
			raise base.FormatError


		except ( IndexError, KeyError ):
			raise base.FormatError


		# import entries into entrystore
		entrystore = data.EntryStore()
		folders = {}

		for node in dom.getElementsByTagName("PasswordItem"):

			parent = None
			e = entry.GenericEntry()

			for fieldnode in [ node for node in node.childNodes if node.nodeType == node.ELEMENT_NODE ]:

				content = self.__decrypt(cipher, util.dom_text(fieldnode))

				if content == "":
					continue

				elif fieldnode.nodeName == "title":
					e.name = content

				elif fieldnode.nodeName == "user":
					e.get_field(entry.UsernameField).value = content

				elif fieldnode.nodeName == "url":
					e.get_field(entry.HostnameField).value = content

				elif fieldnode.nodeName == "password":
					e.get_field(entry.PasswordField).value = content
	
				elif fieldnode.nodeName == "notes":
					e.description = content

				elif fieldnode.nodeName == "category":

					if content in folders:
						parent = folders[content]

					else:
						folderentry = entry.FolderEntry()
						folderentry.name = content

						parent = entrystore.add_entry(folderentry)
						folders[content] = parent

			entrystore.add_entry(e, parent)

		return entrystore