gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r17856 - in gnunet-update: . doc gnunet_update


From: gnunet
Subject: [GNUnet-SVN] r17856 - in gnunet-update: . doc gnunet_update
Date: Sat, 29 Oct 2011 13:09:39 +0200

Author: harsha
Date: 2011-10-29 13:09:39 +0200 (Sat, 29 Oct 2011)
New Revision: 17856

Added:
   gnunet-update/doc/
   gnunet-update/doc/metadata.txt
   gnunet-update/gnunet_update/metadata.py
Modified:
   gnunet-update/gnunet_update/dependency.py
   gnunet-update/gnunet_update/package.py
Log:
added signatures to metadata

Added: gnunet-update/doc/metadata.txt
===================================================================
--- gnunet-update/doc/metadata.txt                              (rev 0)
+++ gnunet-update/doc/metadata.txt      2011-10-29 11:09:39 UTC (rev 17856)
@@ -0,0 +1,49 @@
+File:     doc/metadata.txt
+Author:   Sree Harsha Totakura
+
+* Metadata file:
+  The metadata file consists of sections seperated by a line
+  containing `%%'. Currently there are 3 sections:
+  1. The metadata header which consists of information about the host
+     (the machine on which the package was built)
+  2. The metadata body which is a listing of the dependencies of
+     binary objects in the package
+  3. A listing of signatures of the binary objects to verify the
+     authenticity of each binary object in the package
+
+** Metadata header
+   It consists of information about the host system. This is needed to
+   identify the subset of machine which have the capability to execute
+   the binary objects in the package.
+
+   The header consists of KEY:VALUE pairs with one such pair in each
+   line.
+
+   The valid KEYs are:
+    * MACHINE: 
+      Host machine type. e.g: i386
+    * OS: 
+      Host operating system. e.g: Linux
+    * PKEY: 
+      Public key of the host in hexadecimal digits
+    * RELEASE: 
+      Release number for the package. This is independent of
+      Gnunet release and is intended for packagers and maintainers to
+      identify their own release information
+
+** Metadata body
+   This is a listing of dependencies for each binary object. 
+
+   If a binary object foo needs a shared library libbar.so.X where X
+   is the major number for libbar, the dependency information for A is
+   stored as follows:
+      A;libbar.so.X;X:Y:Z
+   where Y, Z are the minor and revision numbers of libbar.so.X. In
+   case minor and revision numbers for libbar cannot be determined,
+   they are set to -1
+
+** Listing of signatures
+   This is a list of sha512 digest of each file in the package
+   expressed in hexadecimal format. For each file an entry begins with
+   its file name followed by a `:' and then the sha512 digest.
+      file_name: sha512 digest of the file

Modified: gnunet-update/gnunet_update/dependency.py
===================================================================
--- gnunet-update/gnunet_update/dependency.py   2011-10-29 00:55:58 UTC (rev 
17855)
+++ gnunet-update/gnunet_update/dependency.py   2011-10-29 11:09:39 UTC (rev 
17856)
@@ -24,6 +24,7 @@
 #File for holding the Dependency and BinaryObject classes
 
 from operator import xor
+from hashlib import sha512
 
 
 class Dependency:
@@ -47,11 +48,23 @@
 class BinaryObject:
     """Class representing executable code."""
     
-    def __init__(self, name):
+    def __init__(self, path, name=None):
         """Returns am instance of BinaryObject."""
         self.name = name
+        self.path = path
         self._deps = list()
         
+        #Calculate the hash of this binary object
+        hash_obj = sha512()
+        object_file = open(path, "rb")
+        while True:
+            #read 512 bytes - suitable for sha512 blocks
+            data = object_file.read(512)
+            if 0 == len(data): #End of file is reached
+                self.hash = hash_obj.hexdigest()
+                break;
+            hash_obj.update(data);
+        
     def add_dependency(self, dep):
         """Adds dep object to the list of dependencies."""
         self._deps.append(dep)

Added: gnunet-update/gnunet_update/metadata.py
===================================================================
--- gnunet-update/gnunet_update/metadata.py                             (rev 0)
+++ gnunet-update/gnunet_update/metadata.py     2011-10-29 11:09:39 UTC (rev 
17856)
@@ -0,0 +1,98 @@
+# This file is part of GNUnet.
+# (C) 2001--2011 Christian Grothoff (and other contributing authors)
+#
+# GNUnet is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published
+# by the Free Software Foundation; either version 2, or (at your
+# option) any later version.
+#
+# GNUnet is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNUnet; see the file COPYING.  If not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+#File:     gnunet_update/install.py
+#Author:   Sree Harsha Totakura
+#
+#To handle metadata files.
+
+import tempfile
+
+
+class Metadata:
+    """Class for holding metadata information."""
+    _machine = None
+    _os = None
+    _pkey = None
+    _release = None
+    _binary_objects = None
+
+    def __init__(self, machine=None, os=None, pkey=None,
+                 release=None):
+        self._machine = machine
+        self._os = os
+        self._pkey = pkey
+        self._release = release
+
+    def setbinaryobjects(self, binary_objects):
+        """Setter for _binary_objects."""
+        self._binary_objects = binary_objects
+
+    def getbinaryobjects(self):
+        """Getter for binary_objects."""
+        return self._binary_objects
+
+    def writetofile(self, path=None):
+        """Saves metadata to a file and returns the path of that file.
+        
+        path is a string representing the path of the file to be
+        written. If the file doesn't exist a new one is created. If
+        path is None (which is default) then the contents are written
+        to a temporary file and whose path is returned
+        """
+        file_name = None
+        tmp_file = None
+        f = None
+        if None == path:
+            tmp_file = tempfile.NamedTemporaryFile(delete=False)
+            file_name = tmp_file.name
+            f = tmp_file.file
+        else:
+            f = open(path, "wb") #binary mode for compatibility
+            file_name = path
+
+        def __writeln(str): #helper function to get writeln functionality
+            f.write(str + '\n')
+        
+        #write the header
+        if self._machine != None: __writeln("MACHINE:" + 
+                                             self._machine)
+        if self._os != None: __writeln("OS:" + self._os)
+        if self._pkey != None: __writeln("PKEY:" + self._pkey)
+        if self._release != None: __writeln("RELEASE:" + self._release)
+
+        #write the metadata body
+        __writeln("%%") #section seperator
+        for binary_object in self._binary_objects:
+            f.writelines(binary_object.dependency_listlines())
+
+        #write the signatures
+        __writeln("%%") #section seperator
+        for binary_object in self._binary_objects:
+            __writeln(binary_object.name + ":" + binary_object.hash)
+
+        #close file
+        if None == path:
+            tmp_file.close()
+        else:
+            f.close()
+
+        return file_name
+        
+    def readfromfile(self, path):
+        """Reads metadata from the file at path."""

Modified: gnunet-update/gnunet_update/package.py
===================================================================
--- gnunet-update/gnunet_update/package.py      2011-10-29 00:55:58 UTC (rev 
17855)
+++ gnunet-update/gnunet_update/package.py      2011-10-29 11:09:39 UTC (rev 
17856)
@@ -20,7 +20,7 @@
 #File:     gnunet_update/package.py
 #Author:   Sree Harsha Totakura
 #
-#TODO:
+#TODO: Add revision and public key argument
 #
 #Thoughts:
 #            
@@ -37,6 +37,7 @@
 import tarfile
 import platform
 from dependency import Dependency, BinaryObject
+from metadata import Metadata
 
 #global variables
 gnunet_src = ""
@@ -139,7 +140,8 @@
             if 0 != proc.returncode:
                 continue
             #create a new BinaryObject instance and collect its dependencies
-            bin_object = BinaryObject(root[len(install_dir) + 1:] + '/' + file)
+            bin_object = BinaryObject(file_path, 
+                                      root[len(install_dir) + 1:] + '/' + file 
)
             
             for dep_data in map (extract_deps, proc_stdout.splitlines()):
                 #we cannot find a library without its location
@@ -193,24 +195,22 @@
         get_deps(gnunet_src)
     test_dependency_collection()
 
-    metadata_file = tempfile.NamedTemporaryFile()
-    
-    #Add platform specific information to the metadata
-    machine_type = platform.machine();
-    metadata_file.file.writelines(["OS:" + platform.system() + "\n",
-                                   "MACHINE:" + platform.machine() + "\n"])
-     
-    for binary_object in binary_objects:
-        metadata_file.file.writelines(binary_object.dependency_listlines())
-    
+    metadata = Metadata(machine=platform.machine(),
+                        os=platform.system(),
+                        release="0")                       
+    metadata.setbinaryobjects(binary_objects)
+
     #package the installed files
     tar_file = tarfile.open(package_file + ".tgz", 'w:gz')
     tar_file.add(install_prefix, "install-prefix")
     
-    #add the metadata file to tar
-    metadata_file.file.flush()
-    tar_file.add(metadata_file.name, "metadata.dat")
+    #generate the metadata file and add it to tar
+    metadata_file = metadata.writetofile()
+    tar_file.add(metadata_file, "metadata.dat")
     
+    #delete the temporarily generated metadata file
+    os.remove(metadata_file)
+    
     print "Here are the dependencies:"
     for dep in dependencies:
         print dep.name
@@ -224,8 +224,7 @@
         #FIXME: May be delete the temporary directory after packing?
         print "gnunet has been installed into the temp dir: " + install_prefix
         
-    tar_file.close()
-    metadata_file.close()
+    tar_file.close()    
         
 def main():
     """Starting point of execution."""
@@ -270,4 +269,4 @@
         run(action)
 
 if __name__ == "__main__":
-    main()
\ No newline at end of file
+    main()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]