seydar avatar seydar committed 95e6874 Draft

manifest

Comments (0)

Files changed (5)

lib/chitin/commands/executable.rb

 module Chitin
   class Executable
+    # this is needed to work in tandem with #method_missing.
+    # this will sweep all inherited methods BUT #[] under the rug.
     __sweep__ :[]
 
     include Runnable
   
       [path, *arr.flatten].join ' '
     end
+
+    def name; path; end
   
   end
 end

lib/chitin/commands/pipe.rb

       result
     end
 
+    # #verify_permissions does not exist at the instance leve for pipes.
+    # we have to rewrite secure_run and secure_raw_run to take accommodate
+    # them.
+    def secure_run
+      parts.each do |part|
+        part[:verify_permissions, part.name]
+        part[:run]
+      end
+      reset
+  
+      self
+    end
+
+    # see comments of #secure_run
+    def secure_raw_run
+      parts[0..-2].each do |part|
+        part[:verify_permissions, part.name]
+        part[:run]
+      end
+
+      parts.last[:verify_permissions, parts.last[:name]]
+      result = parts.last[:raw_run]
+
+      reset
+  
+      result
+    end
+
     def wait
       parts.each {|part| part[:wait] }
   

lib/chitin/commands/ruby.rb

     def inspect
       "#<StringMethod #{to_s}>"
     end
+
+    def name
+      :ruby
+    end
   end
 end
 

lib/chitin/commands/runnable.rb

       raw_run
     end
 
-    def verify_permissions
+    def verify_permissions(name=self.name)
       # find the manifest file
-      # ask user to confirm
+      manifest = Manifest.find name
+      # ask user to confirm permissions
+      confirmed_perms = manifest.confirm_permissions name
       # take the requested permissions
       #   implement the restrictions according to PinkTrace
+      Sandbox.secure confirmed_perms
     end
+
+    def name; raise "Not Yet Implemented"; end
   end
 end
 

lib/chitin/manifests/manifest.rb

+require 'openssl'
+
+module Chitin
+  class Manifest
+
+    def self.register(hash)
+      @@password_hash = hash
+    end
+
+    # retrieve the manifest entry for the name
+    def self.find(name)
+      manifest_path = File.expand_path '.chitin_manifest'
+      manifest      = File.read manifest_path
+      manifest_hmac = manifest_data[0..511]
+      manifest_data = manifest_data[512..-1]
+
+      # verify the authenticity of the file
+      computed_hmac = OpenSSL::HMAC.hexdigest('sha256',
+                                              @@password_hash,
+                                              manifest_data)
+
+      unless computed_hmac == manifest_hmac
+        puts "MANIFEST FILE HAS BEEN TAMPERED WITH"
+        return {}
+      end
+
+      @@data ||= {}
+      @@data[manifest_path] ||= YAML.load manifest_data
+      @@data[manifest_path][name]
+    end
+
+    def initialize
+    end
+  end
+end
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.